context-engine-mcp
Version:
Context engine MCP server for comprehensive project analysis and multi-file editing
102 lines • 4.24 kB
JavaScript
export var ErrorCodes;
(function (ErrorCodes) {
ErrorCodes["INVALID_PATH"] = "INVALID_PATH";
ErrorCodes["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
ErrorCodes["PERMISSION_DENIED"] = "PERMISSION_DENIED";
ErrorCodes["INVALID_INPUT"] = "INVALID_INPUT";
ErrorCodes["PROCESSING_ERROR"] = "PROCESSING_ERROR";
ErrorCodes["CACHE_ERROR"] = "CACHE_ERROR";
ErrorCodes["DEPENDENCY_ERROR"] = "DEPENDENCY_ERROR";
ErrorCodes["VALIDATION_ERROR"] = "VALIDATION_ERROR";
ErrorCodes["MEMORY_LIMIT_EXCEEDED"] = "MEMORY_LIMIT_EXCEEDED";
ErrorCodes["FILE_SIZE_LIMIT_EXCEEDED"] = "FILE_SIZE_LIMIT_EXCEEDED";
ErrorCodes["TIMEOUT_ERROR"] = "TIMEOUT_ERROR";
ErrorCodes["NETWORK_ERROR"] = "NETWORK_ERROR";
})(ErrorCodes || (ErrorCodes = {}));
export class ContextEngineError extends Error {
code;
context;
timestamp;
constructor(code, message, context, cause) {
super(message);
this.name = 'ContextEngineError';
this.code = code;
this.context = context;
this.timestamp = new Date().toISOString();
if (cause) {
this.cause = cause;
}
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, ContextEngineError);
}
}
toJSON() {
return {
name: this.name,
code: this.code,
message: this.message,
context: this.context,
timestamp: this.timestamp,
stack: this.stack
};
}
}
export class ValidationError extends ContextEngineError {
constructor(message, context) {
super(ErrorCodes.VALIDATION_ERROR, message, context);
this.name = 'ValidationError';
}
}
export class PathValidationError extends ContextEngineError {
constructor(path, reason) {
super(ErrorCodes.INVALID_PATH, `Invalid path: ${path}${reason ? ` - ${reason}` : ''}`, { path, reason });
this.name = 'PathValidationError';
}
}
export class FileNotFoundError extends ContextEngineError {
constructor(path) {
super(ErrorCodes.FILE_NOT_FOUND, `File not found: ${path}`, { path });
this.name = 'FileNotFoundError';
}
}
export class FileSizeLimitError extends ContextEngineError {
constructor(path, size, limit) {
super(ErrorCodes.FILE_SIZE_LIMIT_EXCEEDED, `File size (${size} bytes) exceeds limit (${limit} bytes): ${path}`, { path, size, limit });
this.name = 'FileSizeLimitError';
}
}
export class MemoryLimitError extends ContextEngineError {
constructor(operation, usage, limit) {
super(ErrorCodes.MEMORY_LIMIT_EXCEEDED, `Memory usage (${usage}MB) exceeds limit (${limit}MB) during ${operation}`, { operation, usage, limit });
this.name = 'MemoryLimitError';
}
}
export class ProcessingError extends ContextEngineError {
constructor(operation, details, context) {
super(ErrorCodes.PROCESSING_ERROR, `Processing failed during ${operation}: ${details}`, { operation, details, ...context });
this.name = 'ProcessingError';
}
}
export function isContextEngineError(error) {
return error instanceof Error && 'code' in error && typeof error.code === 'string';
}
export function createErrorFromUnknown(error, defaultMessage = 'Unknown error occurred') {
if (isContextEngineError(error)) {
return error;
}
if (error instanceof Error) {
return new ContextEngineError(ErrorCodes.PROCESSING_ERROR, error.message || defaultMessage, { originalError: error.name }, error);
}
return new ContextEngineError(ErrorCodes.PROCESSING_ERROR, defaultMessage, { originalError: String(error) });
}
export function handleAsyncError(promise, errorContext) {
return promise.catch((error) => {
const contextError = createErrorFromUnknown(error);
// Create a new error with merged context since context is readonly
const mergedContext = { ...contextError.context, ...errorContext };
const newError = new ContextEngineError(contextError.code, contextError.message, mergedContext, contextError.cause);
throw newError;
});
}
//# sourceMappingURL=errors.js.map