diff --git a/assert/unreachable.ts b/assert/unreachable.ts index 6f57feed199a..e58eb81f546a 100644 --- a/assert/unreachable.ts +++ b/assert/unreachable.ts @@ -12,9 +12,10 @@ import { AssertionError } from "./assertion_error.ts"; * unreachable(); // Throws * ``` * - * @param reason The reason why the code should be unreachable. + * @param msg Optional message to include in the error. * @returns Never returns, always throws. */ -export function unreachable(reason?: string): never { - throw new AssertionError(reason ?? "unreachable"); +export function unreachable(msg?: string): never { + const msgSuffix = msg ? `: ${msg}` : "."; + throw new AssertionError(`Unreachable${msgSuffix}`); } diff --git a/assert/unreachable_test.ts b/assert/unreachable_test.ts index 3097c79ebb95..a35a5a26a0f8 100644 --- a/assert/unreachable_test.ts +++ b/assert/unreachable_test.ts @@ -2,10 +2,10 @@ import { AssertionError, assertThrows, unreachable } from "./mod.ts"; Deno.test("unreachable()", () => { - assertThrows(() => unreachable(), AssertionError, "unreachable"); + assertThrows(() => unreachable(), AssertionError, "Unreachable."); assertThrows( () => unreachable("custom message"), AssertionError, - "custom message", + "Unreachable: custom message", ); });