/** * Base error classes and utility functions for error handling. * * Module-specific errors should extend BaseError and live in their own modules. * * @example * ```typescript * // Catching and identifying errors * try { * await workbook.xlsx.readFile('test.xlsx'); * } catch (e) { * if (isExcelError(e)) { * console.error(`Excel error: ${e.message}`); * if (e.cause) console.error('Caused by:', e.cause); * } * } * * // Creating errors with cause chain * throw new ExcelError('Failed to parse', { cause: originalError }); * ``` */ /** * Options for BaseError constructor. */ export interface BaseErrorOptions { /** The original error that caused this error (ES2022 Error Cause) */ cause?: unknown; } /** * Base class for all library errors. * Module-specific errors should extend this class. * * Features: * - Supports ES2022 error cause for error chaining * - Properly captures stack trace * - Sets correct prototype for instanceof checks * - JSON serialization support for logging */ export declare class BaseError extends Error { constructor(message: string, options?: BaseErrorOptions); /** * Serialize error for logging/transmission. * Includes cause chain for debugging. */ toJSON(): Record; } /** * Error thrown when an operation is aborted. */ export declare class AbortError extends BaseError { name: string; readonly code = "ABORT_ERR"; constructor(reason?: unknown); } /** * Create an abort error from a reason. */ export declare function createAbortError(reason?: unknown): AbortError; /** * Check if an error is an abort error. */ export declare function isAbortError(err: unknown): err is { name: string; }; /** * Throw if the signal is aborted. */ export declare function throwIfAborted(signal?: AbortSignal, reason?: unknown): void; /** * Create a linked AbortController that aborts when the parent signal aborts. * * @param parentSignal - Optional parent signal to link to * @returns Controller and cleanup function */ export declare function createLinkedAbortController(parentSignal?: AbortSignal): { controller: AbortController; cleanup: () => void; }; /** * Convert an unknown value to an Error. * * If the value is already an Error, it's returned as-is. * Otherwise, it's converted to a string and wrapped in an Error. * */ export declare function toError(err: unknown): Error; /** * Suppress unhandled rejection warnings for a promise. * * Use this when you intentionally want to ignore a promise's rejection, * typically for fire-and-forget cleanup operations. */ export declare function suppressUnhandledRejection(promise: Promise): void; /** * Serialize any Error to a plain object for logging/transmission. * Handles both BaseError and native Error instances. */ export declare function errorToJSON(err: Error): Record; /** * Get the full error chain as an array. * Useful for logging all errors in a cause chain. * * @example * ```typescript * const chain = getErrorChain(error); * chain.forEach((e, i) => console.log(`${i}: ${e.message}`)); * ``` */ export declare function getErrorChain(err: Error): Error[]; /** * Get the root cause of an error chain. * Returns the deepest error in the cause chain. */ export declare function getRootCause(err: Error): Error;