( condition: boolean, messageOrError: string | Error = 'unexpected state', )
| 42 | * @param messageOrError An error message or error object to throw if condition is `falsy`. |
| 43 | */ |
| 44 | export function assert( |
| 45 | condition: boolean, |
| 46 | messageOrError: string | Error = 'unexpected state', |
| 47 | ): asserts condition { |
| 48 | if (!condition) { |
| 49 | // if error instance is provided, use it, otherwise create a new one |
| 50 | const errorToThrow = typeof messageOrError === 'string' |
| 51 | ? new BugIndicatingError(`Assertion Failed: ${messageOrError}`) |
| 52 | : messageOrError; |
| 53 | |
| 54 | throw errorToThrow; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Like assert, but doesn't throw. |
no outgoing calls
searching dependent graphs…