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:
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.
Import:
import { startAsyncErrorIgnoreContext } from 'obsidian-dev-utils/error';Signature:
function startAsyncErrorIgnoreContext(): DisposableReturns: Disposable — A Disposable that closes the ignore context when disposed, for use with using.
Links to this page: