datapilot-cli
Version:
Enterprise-grade streaming multi-format data analysis with comprehensive statistical insights and intelligent relationship detection - supports CSV, JSON, Excel, TSV, Parquet - memory-efficient, cross-platform
136 lines • 3.79 kB
TypeScript
/**
* Enhanced Error Recovery System
* Comprehensive error handling with automatic recovery and context preservation
*/
import { EventEmitter } from 'events';
export interface ErrorContext {
operation: string;
component: string;
userId?: string;
sessionId?: string;
filePath?: string;
metadata?: any;
retryCount?: number;
startTime?: number;
memoryUsage?: number;
stackTrace?: string;
}
export interface RecoveryStrategy {
name: string;
description: string;
canRecover: (error: Error, context: ErrorContext) => boolean;
recover: (error: Error, context: ErrorContext) => Promise<any>;
priority: number;
maxRetries?: number;
}
export interface ErrorMetrics {
totalErrors: number;
errorsByCategory: {
[category: string]: number;
};
errorsBySeverity: {
[severity: string]: number;
};
recoverySuccessRate: number;
averageRecoveryTime: number;
frequentErrors: Array<{
message: string;
count: number;
}>;
recentErrors: Array<{
timestamp: number;
error: string;
context: ErrorContext;
recovered: boolean;
}>;
}
export interface ErrorHandlerOptions {
enableRecovery?: boolean;
maxRetries?: number;
retryDelays?: number[];
trackMetrics?: boolean;
enableCircuitBreaker?: boolean;
enableResourceTracking?: boolean;
contextEnrichment?: boolean;
}
export declare class EnhancedErrorHandler extends EventEmitter {
private recoveryStrategies;
private errorMetrics;
private options;
private errorHistory;
private recentErrors;
private readonly maxErrorHistory;
constructor(options?: ErrorHandlerOptions);
/**
* Handle an error with automatic recovery attempts
*/
handleError(error: Error, context: ErrorContext, originalOperation?: () => Promise<any>): Promise<{
success: boolean;
result?: any;
finalError?: Error;
}>;
/**
* Wrap a function with automatic error handling
*/
wrapFunction<T extends (...args: any[]) => Promise<any>>(fn: T, context: Partial<ErrorContext>): T;
/**
* Add a custom recovery strategy
*/
addRecoveryStrategy(strategy: RecoveryStrategy): void;
/**
* Attempt recovery using available strategies
*/
private attemptRecovery;
/**
* Enrich error context with additional information
*/
private enrichContext;
/**
* Update error metrics
*/
private updateMetrics;
/**
* Update frequent errors list
*/
private updateFrequentErrors;
/**
* Categorize error for metrics
*/
private categorizeError;
/**
* Get error severity
*/
private getSeverity;
/**
* Initialize default recovery strategies
*/
private initializeDefaultStrategies;
/**
* Get current error metrics
*/
getMetrics(): ErrorMetrics;
/**
* Reset error metrics
*/
resetMetrics(): void;
/**
* Get health status
*/
getHealthStatus(): {
status: 'healthy' | 'degraded' | 'unhealthy';
errorRate: number;
recoveryRate: number;
recommendations: string[];
};
/**
* Shutdown error handler
*/
shutdown(): void;
}
export declare function getGlobalEnhancedErrorHandler(options?: ErrorHandlerOptions): EnhancedErrorHandler;
export declare function shutdownGlobalEnhancedErrorHandler(): void;
/**
* Decorator for automatic error handling
*/
export declare function withErrorHandling<T extends (...args: any[]) => Promise<any>>(context: Partial<ErrorContext>): (target: any, propertyName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
//# sourceMappingURL=enhanced-error-handler.d.ts.map