obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
51 lines (50 loc) • 1.91 kB
text/typescript
/**
* @packageDocumentation
*
* Contains utility functions for error handling.
*/
/**
* The message of the error wrapper that is used to wrap an actual error that occurred during an async operation.
*/
export declare const ASYNC_ERROR_WRAPPER_MESSAGE = "An unhandled error occurred executing async operation";
/**
* Emits an asynchronous error event.
*
* @param asyncError - The error to emit as an asynchronous error event.
*/
export declare function emitAsyncErrorEvent(asyncError: unknown): void;
/**
* Converts an error to a string representation, including nested causes with indentation.
*
* @param error - The error to convert to a string.
* @returns The string representation of the error.
*/
export declare function errorToString(error: unknown): string;
/**
* Gets the current stack trace as a string, excluding the current function call.
*
* @param framesToSkip - The number of frames to skip in the stack trace.
* @returns A string representation of the current stack trace, excluding the current function call.
*/
export declare function getStackTrace(framesToSkip?: number): string;
/**
* Prints an error to the console, including nested causes and optional ANSI sequence clearing.
*
* @param error - The error to print.
* @param console - The console to print to (default: `globalThis.console`).
*/
export declare function printError(error: unknown, console?: Console): void;
/**
* Registers an event handler for asynchronous errors.
*
* @param handler - The handler function to be called when an asynchronous error event occurs.
* @returns A function to unregister the handler.
*/
export declare function registerAsyncErrorEventHandler(handler: (asyncError: unknown) => void): () => void;
/**
* Throws an error with the specified message.
*
* @param error - The error to throw.
* @throws
*/
export declare function throwExpression(error: unknown): never;