Contains utility functions for error handling.
| Class | Description |
|---|
| CustomStackTraceError | An error that wraps an error with a custom stack trace. |
| ErrorWrapper | An error that wraps a non-Error value that was thrown, preserving the original value in cause. |
| SilentError | An error that is not printed to the console. |
| Function | Description |
|---|
| emitAsyncErrorEvent | Emits an asynchronous error event. When a collection window is open (see startCollectingUnhandledAsyncErrors) the error is collected as unhandled unless it is ignored — either because shouldIgnore is true, an startAsyncErrorIgnoreContext scope is active, or a consumer handler is registered. |
| errorToString | Converts an error to a string representation, including nested causes and the aggregated errors of an AggregateError, with indentation. |
| getStackTrace | Gets the current stack trace as a string, excluding the current function call. |
| isAsyncErrorIgnoreContextActive | Checks whether an startAsyncErrorIgnoreContext scope is currently active. |
| printError | Prints an error to the console, including nested causes and optional ANSI sequence clearing. |
| registerAsyncErrorEventHandler | Registers an event handler for asynchronous errors. |
| startAsyncErrorIgnoreContext | Opens an ignore context in which async errors are treated as expected rather than unhandled, so the test harness does not fail the test. While the returned disposable is held, an async error emitted directly (see emitAsyncErrorEvent) is not collected as unhandled. Crucially, a fire-and-forget operation scheduled within the scope (e.g. via async!invokeAsyncSafely) is also ignored when it later rejects — even after the scope has exited — because async!addErrorHandler captures the active ignore context at schedule time. A test therefore does not need to drain the operation itself: ts it('does not fail', () => \{ using _ = startAsyncErrorIgnoreContext(); invokeAsyncSafely(() => Promise.reject(new Error('deliberately swallowed'))); \}); Contexts nest; the ignore only ends once every open context has been disposed. |
| startCollectingUnhandledAsyncErrors | Opens a window in which async errors emitted while no consumer handler is registered are collected as unhandled (see emitAsyncErrorEvent), discarding anything collected by a previous window. Intended for the test harness only: the per-test setup opens a window before each test and drains it after each test via stopCollectingUnhandledAsyncErrors. In production no window is open, so emitting an async error carries no bookkeeping overhead. |
| stopCollectingUnhandledAsyncErrors | Closes the window opened by startCollectingUnhandledAsyncErrors and returns the unhandled async errors collected while it was open. |
| throwExpression | Throws an error with the specified message. |