UNPKG

supa-seed

Version:

A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support

107 lines 3.68 kB
/** * Production Error Handling System * Phase 6, Checkpoint F1 - Comprehensive error handling with logging and recovery */ export interface ErrorContext { operation: string; component: string; userId?: string; metadata?: Record<string, any>; stackTrace?: string; timestamp: Date; } export interface ErrorRecoveryOptions { retryable: boolean; maxRetries?: number; fallbackStrategy?: 'graceful' | 'fail-fast' | 'silent'; userMessage?: string; technicalMessage?: string; } export declare class SupaSeedError extends Error { readonly code: string; readonly context: ErrorContext; readonly recoveryOptions: ErrorRecoveryOptions; readonly severity: 'low' | 'medium' | 'high' | 'critical'; constructor(message: string, code: string, context: ErrorContext, recoveryOptions?: ErrorRecoveryOptions, severity?: 'low' | 'medium' | 'high' | 'critical'); toJSON(): { name: string; message: string; code: string; context: ErrorContext; recoveryOptions: ErrorRecoveryOptions; severity: "low" | "medium" | "high" | "critical"; stack: string | undefined; }; } export declare class ErrorHandler { private static errorCounts; private static errorHistory; private static readonly MAX_HISTORY; /** * Handle an error with comprehensive logging and recovery */ static handle(error: Error | SupaSeedError, context?: Partial<ErrorContext>): Promise<void>; /** * Wrap a generic error in SupaSeedError */ private static wrapError; /** * Log error with appropriate severity */ private static logError; /** * Track error frequency for pattern detection */ private static trackErrorFrequency; /** * Add error to history for analysis */ private static addToHistory; /** * Attempt error recovery based on options */ private static attemptRecovery; /** * Notify external monitoring systems */ private static notifyMonitoring; /** * Get error statistics for monitoring */ static getErrorStats(): { totalErrors: number; errorsByComponent: Record<string, number>; errorsBySeverity: Record<string, number>; topErrors: Array<{ pattern: string; count: number; }>; recentErrors: Array<{ code: string; component: string; timestamp: Date; }>; }; /** * Clear error history and counters */ static clearHistory(): void; /** * Create common error types with predefined configurations */ static createDatabaseError(message: string, context: Partial<ErrorContext>): SupaSeedError; static createAIError(message: string, context: Partial<ErrorContext>): SupaSeedError; static createConfigurationError(message: string, context: Partial<ErrorContext>): SupaSeedError; static createValidationError(message: string, context: Partial<ErrorContext>): SupaSeedError; static createNetworkError(message: string, context: Partial<ErrorContext>): SupaSeedError; } /** * Decorator for automatic error handling */ export declare function handleErrors(component: string, operation?: string, recoveryOptions?: ErrorRecoveryOptions): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void; /** * Async wrapper for error handling */ export declare function withErrorHandling<T>(operation: () => Promise<T>, context: Partial<ErrorContext>, recoveryOptions?: ErrorRecoveryOptions): Promise<T>; export default ErrorHandler; //# sourceMappingURL=error-handler.d.ts.map