codecrucible-synth
Version:
Production-Ready AI Development Platform with Multi-Voice Synthesis, Smithery MCP Integration, Enterprise Security, and Zero-Timeout Reliability
149 lines • 4.65 kB
TypeScript
/**
* Comprehensive Error Handling System
*
* Provides structured error handling, logging, recovery mechanisms,
* and user-friendly error reporting across the entire application.
*/
export declare enum ErrorSeverity {
LOW = "low",
MEDIUM = "medium",
HIGH = "high",
CRITICAL = "critical"
}
export declare enum ErrorCategory {
VALIDATION = "validation",
AUTHENTICATION = "authentication",
AUTHORIZATION = "authorization",
NETWORK = "network",
FILE_SYSTEM = "file_system",
MODEL = "model",
TOOL_EXECUTION = "tool_execution",
CONFIGURATION = "configuration",
SYSTEM = "system",
USER_INPUT = "user_input",
EXTERNAL_API = "external_api",
MCP_SERVICE = "mcp_service",
DATABASE = "database",
TIMEOUT = "timeout",
RATE_LIMIT = "rate_limit",
NOT_FOUND = "not_found",
CONFLICT = "conflict",
SECURITY = "security",
INFRASTRUCTURE = "infrastructure",
APPLICATION = "application"
}
export interface StructuredError {
id: string;
message: string;
category: ErrorCategory;
severity: ErrorSeverity;
timestamp: number;
context?: Record<string, any>;
stackTrace?: string;
userMessage?: string;
suggestedActions?: string[];
recoverable: boolean;
retryable: boolean;
metadata?: Record<string, any>;
}
export interface ErrorResponse {
success: false;
error: StructuredError;
request_id?: string;
service?: string;
recovery_suggestions?: string[];
}
export interface SuccessResponse<T = any> {
success: true;
data: T;
request_id?: string;
service?: string;
metadata?: Record<string, any>;
}
export type ServiceResponse<T = any> = SuccessResponse<T> | ErrorResponse;
/**
* Error factory for creating structured errors
*/
export declare class ErrorFactory {
private static errorCounter;
static createError(message: string, category: ErrorCategory, severity?: ErrorSeverity, options?: {
context?: Record<string, any>;
userMessage?: string;
suggestedActions?: string[];
recoverable?: boolean;
retryable?: boolean;
metadata?: Record<string, any>;
originalError?: Error;
}): StructuredError;
private static generateUserMessage;
private static generateSuggestedActions;
private static isRecoverable;
private static isRetryable;
}
/**
* Error handler with recovery mechanisms
*/
export declare class ErrorHandler {
private static errorHistory;
private static maxHistorySize;
/**
* Handle error with logging and potential recovery
*/
static handleError(error: Error | StructuredError, context?: Record<string, any>): Promise<StructuredError>;
/**
* Create error response for APIs and tools
*/
static createErrorResponse(error: Error | StructuredError, requestId?: string, service?: string): ErrorResponse;
/**
* Create success response
*/
static createSuccessResponse<T>(data: T, requestId?: string, service?: string, metadata?: Record<string, any>): SuccessResponse<T>;
/**
* Wrap function with error handling
*/
static wrapWithErrorHandling<T extends any[], R>(fn: (...args: T) => Promise<R>, context?: Record<string, any>): (...args: T) => Promise<ServiceResponse<R>>;
/**
* Retry function with exponential backoff
*/
static retryWithBackoff<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?: number, context?: Record<string, any>): Promise<ServiceResponse<T>>;
/**
* Get error statistics
*/
static getErrorStatistics(): {
total: number;
by_category: Record<ErrorCategory, number>;
by_severity: Record<ErrorSeverity, number>;
recent_errors: StructuredError[];
};
/**
* Clear error history
*/
static clearErrorHistory(): void;
private static ensureStructuredError;
private static logError;
private static attemptRecovery;
}
/**
* Input validation with structured error responses
*/
export declare class InputValidator {
/**
* Validate required string field
*/
static validateString(value: any, fieldName: string, options?: {
minLength?: number;
maxLength?: number;
pattern?: RegExp;
allowEmpty?: boolean;
}): ServiceResponse<string>;
/**
* Validate and sanitize file path
*/
static validateFilePath(path: any): ServiceResponse<string>;
/**
* Sanitize user input to prevent injection attacks
*/
static sanitizeInput(input: string): string;
}
export default ErrorHandler;
//# sourceMappingURL=structured-error-system.d.ts.map