UNPKG

erosolar-cli

Version:

Unified AI agent framework for the command line - Multi-provider support with schema-driven tools, code intelligence, and transparent reasoning

87 lines 2.96 kB
/** * Enhanced Error Handling Utilities * * Provides TypeScript-first error handling patterns with: * - Result types for functional error handling * - Async error recovery strategies * - Structured error classification * - Automatic error recovery suggestions */ import { ErrorCategory, ErrorSeverity, type StructuredError } from './errorTypes.js'; /** * Result type for functional error handling */ export type Result<T, E = Error> = { success: true; data: T; } | { success: false; error: E; }; /** * Async result type for promise-based operations */ export type AsyncResult<T, E = Error> = Promise<Result<T, E>>; /** * Error recovery strategy */ export interface ErrorRecoveryStrategy { readonly id: string; readonly label: string; readonly description: string; readonly action: () => unknown; readonly autoRecoverable: boolean; readonly confidence: 'high' | 'medium' | 'low'; } /** * Enhanced error with recovery strategies */ export interface RecoverableError extends Error { readonly category: ErrorCategory; readonly severity: ErrorSeverity; readonly recoveryStrategies: ErrorRecoveryStrategy[]; readonly structured?: StructuredError; } /** * Create a recoverable error */ export declare function createRecoverableError(message: string, category: ErrorCategory, severity: ErrorSeverity, recoveryStrategies: ErrorRecoveryStrategy[], structured?: StructuredError): RecoverableError; /** * Wrap a function with error recovery */ export declare function withErrorRecovery<T, Args extends unknown[]>(fn: (...args: Args) => T | Promise<T>, recoveryStrategies: ErrorRecoveryStrategy[]): (...args: Args) => Promise<T>; /** * Execute with automatic retry on recoverable errors */ export declare function executeWithRetry<T>(operation: () => Promise<T>, maxRetries?: number, delayMs?: number): Promise<T>; /** * Check if error is recoverable */ export declare function isRecoverableError(error: unknown): error is RecoverableError; /** * Extract recovery strategies from error */ export declare function extractRecoveryStrategies(error: unknown): ErrorRecoveryStrategy[]; /** * Safe async execution with result type */ export declare function safeAsync<T>(operation: () => Promise<T>): AsyncResult<T>; /** * Safe synchronous execution with result type */ export declare function safeSync<T>(operation: () => T): Result<T>; /** * Chain multiple operations with error handling */ export declare function chainOperations<T>(operations: Array<() => Promise<T>>): () => Promise<Result<T>>; /** * Error handler registry for centralized error management */ export declare class ErrorHandlerRegistry { private handlers; register(handlerId: string, handler: (error: unknown) => void): void; unregister(handlerId: string): void; handle(error: unknown): void; } export declare const globalErrorHandlers: ErrorHandlerRegistry; //# sourceMappingURL=errorUtils.d.ts.map