2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-10 02:43:44 +00:00
|
|
|
// This module is browser compatible.
|
2024-06-03 13:30:20 +00:00
|
|
|
import { AssertionError } from "./assertion_error.ts";
|
2023-07-13 07:04:30 +00:00
|
|
|
|
|
|
|
/**
|
2023-12-06 17:13:38 +00:00
|
|
|
* Forcefully throws a failed assertion.
|
|
|
|
*
|
2024-05-30 02:38:16 +00:00
|
|
|
* @example Usage
|
|
|
|
* ```ts no-eval
|
2024-04-29 02:57:30 +00:00
|
|
|
* import { fail } from "@std/assert/fail";
|
2023-12-06 17:13:38 +00:00
|
|
|
*
|
|
|
|
* fail("Deliberately failed!"); // Throws
|
|
|
|
* ```
|
2024-05-30 02:38:16 +00:00
|
|
|
*
|
|
|
|
* @param msg Optional message to include in the error.
|
|
|
|
* @returns Never returns, always throws.
|
2023-07-13 07:04:30 +00:00
|
|
|
*/
|
|
|
|
export function fail(msg?: string): never {
|
|
|
|
const msgSuffix = msg ? `: ${msg}` : ".";
|
2024-06-03 13:30:20 +00:00
|
|
|
throw new AssertionError(`Failed assertion${msgSuffix}`);
|
2023-07-13 07:04:30 +00:00
|
|
|
}
|