UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

75 lines (74 loc) 2.5 kB
/** * @packageDocumentation * * Contains utility functions for error handling. */ /** * A message of the AsyncWrapperError. */ export declare const ASYNC_WRAPPER_ERROR_MESSAGE = "An unhandled error occurred executing async operation"; /** * An error that wraps an error with a custom stack trace. */ export declare class CustomStackTraceError extends Error { /** * Creates a new CustomStackTraceError. * * @param message - The message of the error. * @param stackTrace - The stack trace of the error. * @param cause - The cause of the error. */ constructor(message: string, stackTrace: string, cause: unknown); } /** * An error that is not printed to the console. */ export declare class SilentError extends Error { /** * Creates a new SilentError. * * @param message - The message of the error. */ constructor(message: string); } /** * 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;