/** * Error Handling System * * Provides a standardized error handling system with dual-message format: * - userMessage: Friendly message for end users (no technical details) * - developerMessage: Technical details for debugging * * All errors across the codebase use this system for consistent error reporting. */ /** * Error codes for all MCP errors * Based on RFC Section 6: Error Handling */ export declare enum ErrorCode { /** Index not found for the given project path */ INDEX_NOT_FOUND = "INDEX_NOT_FOUND", /** Failed to download or initialize the embedding model */ MODEL_DOWNLOAD_FAILED = "MODEL_DOWNLOAD_FAILED", /** Index data is corrupted or unreadable */ INDEX_CORRUPT = "INDEX_CORRUPT", /** File count exceeds recommended limit (warning, not error) */ FILE_LIMIT_WARNING = "FILE_LIMIT_WARNING", /** Insufficient permissions to access path */ PERMISSION_DENIED = "PERMISSION_DENIED", /** Insufficient disk space for operation */ DISK_FULL = "DISK_FULL", /** Requested file does not exist */ FILE_NOT_FOUND = "FILE_NOT_FOUND", /** Invalid glob or regex pattern */ INVALID_PATTERN = "INVALID_PATTERN", /** Could not detect project root from given path */ PROJECT_NOT_DETECTED = "PROJECT_NOT_DETECTED", /** Symbolic link not allowed for security reasons */ SYMLINK_NOT_ALLOWED = "SYMLINK_NOT_ALLOWED", /** Invalid file or directory path */ INVALID_PATH = "INVALID_PATH", /** Failed to extract data from file */ EXTRACTION_FAILED = "EXTRACTION_FAILED" } /** * Interface for MCP error structure */ export interface MCPErrorOptions { code: ErrorCode; userMessage: string; developerMessage: string; cause?: Error; } /** * Custom error class for MCP errors with dual messages * * Extends Error to provide: * - Separate user-friendly and developer messages * - Proper stack trace capture * - JSON serialization for MCP responses * - Integration with logging system */ export declare class MCPError extends Error { /** Error code for programmatic handling */ readonly code: ErrorCode; /** User-friendly message (safe to display to end users) */ readonly userMessage: string; /** Technical message with debugging details */ readonly developerMessage: string; /** Original error that caused this error */ readonly cause?: Error; constructor(options: MCPErrorOptions); /** * Log the error using the logger system */ private logError; /** * Convert error to JSON for MCP responses */ toJSON(): Record; /** * Get a string representation suitable for logging */ toString(): string; } /** * Create an INDEX_NOT_FOUND error * * Used when no index exists for a project path. * * @param indexPath - The path where the index was expected */ export declare function indexNotFound(indexPath: string): MCPError; /** * Create a MODEL_DOWNLOAD_FAILED error * * Used when the embedding model fails to download or initialize. * * @param error - The underlying error that caused the failure */ export declare function modelDownloadFailed(error: Error): MCPError; /** * Create an INDEX_CORRUPT error * * Used when index data is corrupted or unreadable. * * @param details - Technical details about the corruption */ export declare function indexCorrupt(details: string): MCPError; /** * Create a FILE_LIMIT_WARNING error * * Used when file count exceeds recommended limits. * Note: This is a warning, not a blocking error. * * @param count - Current number of files * @param limit - Recommended file limit */ export declare function fileLimitWarning(count: number, limit: number): MCPError; /** * Create a PERMISSION_DENIED error * * Used when access to a path is denied. * * @param filePath - The path that could not be accessed */ export declare function permissionDenied(filePath: string): MCPError; /** * Create a DISK_FULL error * * Used when there is insufficient disk space. * * @param needed - Bytes needed for the operation * @param available - Bytes currently available */ export declare function diskFull(needed: number, available: number): MCPError; /** * Create a FILE_NOT_FOUND error * * Used when a requested file does not exist. * * @param filePath - The path to the missing file */ export declare function fileNotFound(filePath: string): MCPError; /** * Create an INVALID_PATTERN error * * Used when a glob or regex pattern is invalid. * * @param pattern - The invalid pattern * @param errorDetail - Description of what's wrong with the pattern */ export declare function invalidPattern(pattern: string, errorDetail: string): MCPError; /** * Create a PROJECT_NOT_DETECTED error * * Used when a project root cannot be determined. * * @param searchedPath - The path that was searched */ export declare function projectNotDetected(searchedPath: string): MCPError; /** * Create a SYMLINK_NOT_ALLOWED error * * Used when a symbolic link is detected where it's not allowed for security reasons. * Symlinks can be used to read files outside the project directory. * * @param filePath - The path to the symlink */ export declare function symlinkNotAllowed(filePath: string): MCPError; /** * Type guard to check if an error is an MCPError */ export declare function isMCPError(error: unknown): error is MCPError; /** * Wrap an unknown error as an MCPError if it isn't already * * Useful for catch blocks where you want to ensure consistent error handling. * * @param error - The error to wrap * @param defaultCode - Error code to use if wrapping a non-MCPError * @param context - Additional context for the error message */ export declare function wrapError(error: unknown, defaultCode?: ErrorCode, context?: string): MCPError; //# sourceMappingURL=index.d.ts.map