UNPKG

superaugment

Version:

Enterprise-grade MCP server with world-class C++ analysis, robust error handling, and production-ready architecture for VS Code Augment

206 lines 8.51 kB
/** * SuperAugment Error Types * * Defines standardized error types and error codes for consistent error handling * across all tools and components in the SuperAugment MCP server. */ /** * Standard error codes for SuperAugment */ export var ErrorCode; (function (ErrorCode) { // General errors (1000-1099) ErrorCode[ErrorCode["UNKNOWN_ERROR"] = 1000] = "UNKNOWN_ERROR"; ErrorCode[ErrorCode["INVALID_INPUT"] = 1001] = "INVALID_INPUT"; ErrorCode[ErrorCode["INVALID_CONFIGURATION"] = 1002] = "INVALID_CONFIGURATION"; ErrorCode[ErrorCode["INITIALIZATION_FAILED"] = 1003] = "INITIALIZATION_FAILED"; // Tool execution errors (1100-1199) ErrorCode[ErrorCode["TOOL_NOT_FOUND"] = 1100] = "TOOL_NOT_FOUND"; ErrorCode[ErrorCode["TOOL_EXECUTION_FAILED"] = 1101] = "TOOL_EXECUTION_FAILED"; ErrorCode[ErrorCode["TOOL_TIMEOUT"] = 1102] = "TOOL_TIMEOUT"; ErrorCode[ErrorCode["TOOL_INVALID_ARGUMENTS"] = 1103] = "TOOL_INVALID_ARGUMENTS"; // File system errors (1200-1299) ErrorCode[ErrorCode["FILE_NOT_FOUND"] = 1200] = "FILE_NOT_FOUND"; ErrorCode[ErrorCode["FILE_READ_ERROR"] = 1201] = "FILE_READ_ERROR"; ErrorCode[ErrorCode["FILE_WRITE_ERROR"] = 1202] = "FILE_WRITE_ERROR"; ErrorCode[ErrorCode["DIRECTORY_NOT_FOUND"] = 1203] = "DIRECTORY_NOT_FOUND"; ErrorCode[ErrorCode["PERMISSION_DENIED"] = 1204] = "PERMISSION_DENIED"; ErrorCode[ErrorCode["FILE_TOO_LARGE"] = 1205] = "FILE_TOO_LARGE"; // Configuration errors (1300-1399) ErrorCode[ErrorCode["CONFIG_LOAD_FAILED"] = 1300] = "CONFIG_LOAD_FAILED"; ErrorCode[ErrorCode["CONFIG_VALIDATION_FAILED"] = 1301] = "CONFIG_VALIDATION_FAILED"; ErrorCode[ErrorCode["CONFIG_FILE_NOT_FOUND"] = 1302] = "CONFIG_FILE_NOT_FOUND"; ErrorCode[ErrorCode["CONFIG_PARSE_ERROR"] = 1303] = "CONFIG_PARSE_ERROR"; ErrorCode[ErrorCode["VALIDATION_FAILED"] = 1304] = "VALIDATION_FAILED"; // Analysis errors (1400-1499) ErrorCode[ErrorCode["ANALYSIS_FAILED"] = 1400] = "ANALYSIS_FAILED"; ErrorCode[ErrorCode["UNSUPPORTED_FILE_TYPE"] = 1401] = "UNSUPPORTED_FILE_TYPE"; ErrorCode[ErrorCode["PARSING_ERROR"] = 1402] = "PARSING_ERROR"; ErrorCode[ErrorCode["ANALYSIS_TIMEOUT"] = 1403] = "ANALYSIS_TIMEOUT"; // Resource errors (1500-1599) ErrorCode[ErrorCode["RESOURCE_NOT_FOUND"] = 1500] = "RESOURCE_NOT_FOUND"; ErrorCode[ErrorCode["RESOURCE_ACCESS_DENIED"] = 1501] = "RESOURCE_ACCESS_DENIED"; ErrorCode[ErrorCode["RESOURCE_CORRUPTED"] = 1502] = "RESOURCE_CORRUPTED"; // Network/External errors (1600-1699) ErrorCode[ErrorCode["NETWORK_ERROR"] = 1600] = "NETWORK_ERROR"; ErrorCode[ErrorCode["EXTERNAL_SERVICE_ERROR"] = 1601] = "EXTERNAL_SERVICE_ERROR"; ErrorCode[ErrorCode["TIMEOUT_ERROR"] = 1602] = "TIMEOUT_ERROR"; // Memory/Performance errors (1700-1799) ErrorCode[ErrorCode["OUT_OF_MEMORY"] = 1700] = "OUT_OF_MEMORY"; ErrorCode[ErrorCode["PERFORMANCE_THRESHOLD_EXCEEDED"] = 1701] = "PERFORMANCE_THRESHOLD_EXCEEDED"; ErrorCode[ErrorCode["RESOURCE_EXHAUSTED"] = 1702] = "RESOURCE_EXHAUSTED"; })(ErrorCode || (ErrorCode = {})); /** * Error severity levels */ export var ErrorSeverity; (function (ErrorSeverity) { ErrorSeverity["LOW"] = "low"; ErrorSeverity["MEDIUM"] = "medium"; ErrorSeverity["HIGH"] = "high"; ErrorSeverity["CRITICAL"] = "critical"; })(ErrorSeverity || (ErrorSeverity = {})); /** * Base SuperAugment error class */ export class SuperAugmentError extends Error { code; severity; context; isRetryable; originalError; constructor(message, code, severity = ErrorSeverity.MEDIUM, context = {}, isRetryable = false, originalError) { super(message); this.name = 'SuperAugmentError'; this.code = code; this.severity = severity; this.context = { ...context, timestamp: context.timestamp || new Date(), }; this.isRetryable = isRetryable; if (originalError) { this.originalError = originalError; } // Maintain proper stack trace if (Error.captureStackTrace) { Error.captureStackTrace(this, SuperAugmentError); } } /** * Convert error to JSON for logging and serialization */ toJSON() { return { name: this.name, message: this.message, code: this.code, severity: this.severity, context: this.context, isRetryable: this.isRetryable, stack: this.stack, originalError: this.originalError ? { name: this.originalError.name, message: this.originalError.message, stack: this.originalError.stack, } : undefined, }; } /** * Get user-friendly error message */ getUserMessage() { switch (this.code) { case ErrorCode.FILE_NOT_FOUND: return `File not found: ${this.context.filePath || 'unknown'}`; case ErrorCode.FILE_TOO_LARGE: return 'File is too large to process. Please try with a smaller file.'; case ErrorCode.TOOL_NOT_FOUND: return `Tool '${this.context.toolName || 'unknown'}' is not available.`; case ErrorCode.INVALID_INPUT: return 'Invalid input provided. Please check your parameters.'; case ErrorCode.OUT_OF_MEMORY: return 'Not enough memory to complete the operation. Please try with smaller files.'; default: return this.message; } } } /** * Tool execution specific error */ export class ToolExecutionError extends SuperAugmentError { constructor(message, toolName, code = ErrorCode.TOOL_EXECUTION_FAILED, context = {}, originalError) { super(message, code, ErrorSeverity.HIGH, { ...context, toolName }, false, originalError); this.name = 'ToolExecutionError'; } } /** * File system specific error */ export class FileSystemError extends SuperAugmentError { constructor(message, filePath, code, context = {}, originalError) { super(message, code, ErrorSeverity.MEDIUM, { ...context, filePath }, true, // File system errors are often retryable originalError); this.name = 'FileSystemError'; } } /** * Configuration specific error */ export class ConfigurationError extends SuperAugmentError { constructor(message, code = ErrorCode.CONFIG_VALIDATION_FAILED, context = {}, originalError) { super(message, code, ErrorSeverity.HIGH, context, false, // Configuration errors are usually not retryable originalError); this.name = 'ConfigurationError'; } } /** * Analysis specific error */ export class AnalysisError extends SuperAugmentError { constructor(message, code = ErrorCode.ANALYSIS_FAILED, context = {}, originalError) { super(message, code, ErrorSeverity.MEDIUM, context, true, // Analysis errors might be retryable originalError); this.name = 'AnalysisError'; } } /** * Resource specific error */ export class ResourceError extends SuperAugmentError { constructor(message, code = ErrorCode.RESOURCE_NOT_FOUND, context = {}, originalError) { super(message, code, ErrorSeverity.MEDIUM, context, true, // Resource errors might be retryable originalError); this.name = 'ResourceError'; } } /** * Performance specific error */ export class PerformanceError extends SuperAugmentError { constructor(message, code = ErrorCode.PERFORMANCE_THRESHOLD_EXCEEDED, context = {}, originalError) { super(message, code, ErrorSeverity.HIGH, context, false, // Performance errors are usually not retryable originalError); this.name = 'PerformanceError'; } } /** * Utility function to check if an error is a SuperAugment error */ export function isSuperAugmentError(error) { return error instanceof SuperAugmentError; } /** * Utility function to wrap unknown errors into SuperAugment errors */ export function wrapError(error, message, code = ErrorCode.UNKNOWN_ERROR, context = {}) { if (isSuperAugmentError(error)) { return error; } if (error instanceof Error) { return new SuperAugmentError(message || error.message, code, ErrorSeverity.MEDIUM, context, false, error); } return new SuperAugmentError(message || 'Unknown error occurred', code, ErrorSeverity.MEDIUM, context); } //# sourceMappingURL=ErrorTypes.js.map