/** * ErrorHandler * * Centralized error handling utility for the design system. * Provides consistent error handling, logging, and reporting. */ import { DesignSystemError, type ErrorMetadata } from './DesignSystemError'; import type { Result } from './types/Result'; export declare class ErrorHandler { /** * Handle and normalize errors * Converts any error type to DesignSystemError */ static handle(error: unknown, context?: string, additionalContext?: Record): DesignSystemError; /** * Log error to console (only in development) */ static log(error: DesignSystemError | Error | unknown): void; /** * Handle error with logging * Combines handle() and log() for convenience */ static handleAndLog(error: unknown, context?: string, additionalContext?: Record): DesignSystemError; /** * Create a new DesignSystemError with specific code */ static create(message: string, code: string, context?: Record): DesignSystemError; /** * Wrap async function with error handling * Returns [error, result] tuple (similar to Go pattern) */ static tryAsync(fn: () => Promise, context?: string): Promise<[DesignSystemError | null, T | null]>; /** * Wrap sync function with error handling * Returns [error, result] tuple */ static try(fn: () => T, context?: string): [DesignSystemError | null, T | null]; /** * Normalize any error to DesignSystemError with metadata */ static normalize(error: unknown, code: string, metadata?: ErrorMetadata): DesignSystemError; /** * Wrap async function with timeout */ static withTimeout(promise: Promise, timeoutMs: number, context?: string): Promise; /** * Wrap async function returning Result type */ static tryAsyncResult(fn: () => Promise, code: string, metadata?: ErrorMetadata): Promise>; /** * Wrap sync function returning Result type */ static tryResult(fn: () => T, code: string, metadata?: ErrorMetadata): Result; }