/** * MCP-compliant error handling system for In Memoria * Provides structured error types following JSON-RPC 2.0 specification * Compatible with Model Context Protocol requirements */ export declare enum MCPErrorCode { PARSE_ERROR = -32700, INVALID_REQUEST = -32600, METHOD_NOT_FOUND = -32601, INVALID_PARAMS = -32602, INTERNAL_ERROR = -32603, RESOURCE_NOT_FOUND = -32001, RESOURCE_ACCESS_DENIED = -32002, TOOL_EXECUTION_FAILED = -32003, PROTOCOL_VIOLATION = -32004, INITIALIZATION_FAILED = -32005, TRANSPORT_ERROR = -32006, AUTHENTICATION_FAILED = -32007, SESSION_EXPIRED = -32008, RATE_LIMITED = -32009, SERVICE_UNAVAILABLE = -32010 } export declare enum ErrorCode { PLATFORM_UNSUPPORTED = 1001, NATIVE_BINDING_FAILED = 1002, DATABASE_INIT_FAILED = 1003, DATABASE_MIGRATION_FAILED = 1004, VECTOR_DB_INIT_FAILED = 1005, CIRCUIT_BREAKER_OPEN = 1006, FILE_NOT_FOUND = 2001, FILE_READ_FAILED = 2002, FILE_WRITE_FAILED = 2003, DIRECTORY_NOT_FOUND = 2004, PERMISSION_DENIED = 2005, INVALID_PATH = 2006, LANGUAGE_UNSUPPORTED = 3001, PARSE_FAILED = 3002, TREE_SITTER_FAILED = 3003, CONCEPT_EXTRACTION_FAILED = 3004, PATTERN_ANALYSIS_FAILED = 3005, SEMANTIC_ANALYSIS_FAILED = 3006, INVALID_CONFIG = 4001, MISSING_CONFIG = 4002, CONFIG_VALIDATION_FAILED = 4003, SETUP_INCOMPLETE = 4004, NETWORK_TIMEOUT = 5001, EXTERNAL_SERVICE_FAILED = 5002, RATE_LIMIT_EXCEEDED = 5003, INVALID_ARGS = 6001, MISSING_ARGS = 6002, VALIDATION_FAILED = 6003 } export declare enum ErrorSeverity { LOW = "low", MEDIUM = "medium", HIGH = "high", CRITICAL = "critical" } export interface ErrorContext { operation?: string; filePath?: string; language?: string; component?: string; timestamp?: Date; stack?: string; additionalInfo?: Record; } export interface RecoveryAction { description: string; command?: string; automated?: boolean; } /** * MCP-compliant error response following JSON-RPC 2.0 specification */ export interface MCPErrorResponse { code: MCPErrorCode; message: string; data?: { type?: string; context?: ErrorContext; recoveryActions?: RecoveryAction[]; timestamp?: string; requestId?: string; [key: string]: any; }; } /** * JSON-RPC 2.0 error object for MCP protocol compliance */ export interface JSONRPCError { jsonrpc: '2.0'; error: MCPErrorResponse; id: string | number | null; } export declare class InMemoriaError extends Error { readonly code: ErrorCode; readonly severity: ErrorSeverity; readonly context: ErrorContext; readonly recoveryActions: RecoveryAction[]; readonly userMessage: string; readonly originalError?: Error; constructor(code: ErrorCode, message: string, userMessage: string, severity?: ErrorSeverity, context?: ErrorContext, recoveryActions?: RecoveryAction[], originalError?: Error); /** * Get a formatted error message for display to users */ getFormattedMessage(): string; /** * Convert to a JSON-serializable object */ toJSON(): { name: string; code: ErrorCode; message: string; userMessage: string; severity: ErrorSeverity; context: ErrorContext; recoveryActions: RecoveryAction[]; originalError: string | undefined; }; /** * Convert to MCP-compliant error response */ toMCPError(requestId?: string | number): MCPErrorResponse; /** * Convert to JSON-RPC 2.0 error response */ toJSONRPCError(requestId: string | number | null): JSONRPCError; /** * Map internal error codes to MCP error codes */ private getMCPErrorCode; } /** * Factory functions for creating common errors with appropriate context */ export declare class ErrorFactory { static platformUnsupported(platform: string, arch: string): InMemoriaError; static nativeBindingFailed(originalError: Error, platform?: string): InMemoriaError; static fileNotFound(filePath: string, operation: string): InMemoriaError; static languageUnsupported(language: string, filePath?: string): InMemoriaError; static parseFailed(filePath: string, language: string, originalError?: Error): InMemoriaError; static databaseInitFailed(dbPath: string, originalError: Error): InMemoriaError; static invalidConfig(configPath: string, validationErrors: string[]): InMemoriaError; static circuitBreakerOpen(component: string, lastFailure?: Date): InMemoriaError; } /** * MCP-specific utility functions for error handling */ export declare class MCPErrorUtils { /** * Create a standard MCP error response from an MCPErrorCode */ static createMCPError(code: MCPErrorCode, message: string, data?: MCPErrorResponse['data']): MCPErrorResponse; /** * Create a JSON-RPC error response */ static createJSONRPCError(code: MCPErrorCode, message: string, requestId: string | number | null, data?: MCPErrorResponse['data']): JSONRPCError; /** * Wrap tool execution errors for MCP compliance */ static wrapToolError(toolName: string, error: unknown, requestId?: string | number): JSONRPCError; /** * Handle resource access errors */ static resourceNotFound(resourceType: string, resourceId: string, requestId?: string | number): JSONRPCError; /** * Handle invalid parameter errors */ static invalidParams(paramName: string, expected: string, received: unknown, requestId?: string | number): JSONRPCError; } /** * Utility functions for error handling */ export declare class ErrorUtils { /** * Safely extract error message from unknown error */ static getErrorMessage(error: unknown): string; /** * Check if error is recoverable */ static isRecoverable(error: InMemoriaError): boolean; /** * Log error with appropriate level */ static logError(error: InMemoriaError): void; private static getSeverityLogLevel; /** * Convert standard Error to InMemoriaError */ static fromError(error: Error, context?: ErrorContext): InMemoriaError; } //# sourceMappingURL=error-types.d.ts.map