//#region src/error_serializer.d.ts /** * Error serialization utilities inspired by pino-std-serializers. * Handles error cause chains with circular reference protection. * * @see https://github.com/pinojs/pino-std-serializers */ /** * Context frame with source code lines (same as in context_lines.ts). */ interface ContextFrame { filename: string; platform?: string; lineno: number; colno?: number; function?: string; in_app: boolean; pre_context: string[]; context_line: string; post_context: string[]; } interface ErrorCause { type: string; message: string; stack?: string; frames?: ContextFrame[]; } interface StructuredExceptionMechanism { type: string; handled: boolean; synthetic: boolean; exception_id: number; parent_id?: number; source?: string; is_exception_group?: boolean; } interface StructuredException { id: number; parent_id?: number; source?: string; type: string; message: string; stacktrace?: string; frames?: ContextFrame[]; mechanism: StructuredExceptionMechanism; } interface BuildExceptionValuesOptions { value: unknown; fallbackError?: Error; causeChain?: ErrorCause[]; rootMechanism?: { type?: string; handled?: boolean; }; } /** * Maximum number of causes to capture (prevents infinite loops). */ declare const MAX_CAUSE_DEPTH = 5; declare const MAX_EXCEPTION_VALUES = 20; declare const MAX_AGGREGATE_CHILDREN = 10; /** * Check if a value is error-like (has a message property). */ declare function isErrorLike(err: unknown): err is Error; /** * Safely extract the cause from an error. * Handles both standard Error.cause and VError-style cause() functions. */ declare function getErrorCause(err: Error): Error | undefined; declare function getExceptionType(value: unknown): string; declare function getExceptionMessage(value: unknown): string; /** * Build structured exception values with parent/child metadata for grouping. */ declare function buildExceptionValues(options: BuildExceptionValuesOptions): StructuredException[]; /** * Build a combined stack trace from an error and all its causes. * Format: * Error: Top-level message * at file.js:10:5 * caused by: Error: Mid-level message * at file.js:20:3 */ declare function stackWithCauses(err: Error): string; /** * Build a structured cause chain from an error. * Returns an array of { type, message, stack } objects. * Limited to MAX_CAUSE_DEPTH to prevent infinite loops. */ declare function buildCauseChain(err: Error): ErrorCause[]; /** * Build a flattened message from an error and all its causes. * Format: "Top-level message: Mid-level message: Low-level message" * * Note: This format can be ambiguous if messages contain colons. * Prefer using buildCauseChain() for structured data. */ declare function messageWithCauses(err: Error): string; //#endregion export { ContextFrame, ErrorCause, MAX_AGGREGATE_CHILDREN, MAX_CAUSE_DEPTH, MAX_EXCEPTION_VALUES, StructuredException, StructuredExceptionMechanism, buildCauseChain, buildExceptionValues, getErrorCause, getExceptionMessage, getExceptionType, isErrorLike, messageWithCauses, stackWithCauses };