Skip to content

Commit

Permalink
BREAKING(assert): make unreachable() consistent with @std/assert (#…
Browse files Browse the repository at this point in the history
…4943)

* BREAKING(assert): make `unreachable()` consistent with `@std/assert`

* fix

* fix
  • Loading branch information
iuioiua authored Jun 3, 2024
1 parent e34245b commit c2b5460
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions assert/unreachable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
4 changes: 2 additions & 2 deletions assert/unreachable_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});

0 comments on commit c2b5460

Please sign in to comment.