UNPKG

@memory-bank/mcp

Version:

Memory-enabled Co-Pilot (MCP) server for managing project documentation and context

141 lines 5.85 kB
import { BaseError } from './BaseError.js'; /** * Error codes for the infrastructure layer */ export var InfrastructureErrorCodes; (function (InfrastructureErrorCodes) { InfrastructureErrorCodes["FILE_NOT_FOUND"] = "INFRASTRUCTURE_FILE_NOT_FOUND"; InfrastructureErrorCodes["FILE_READ_ERROR"] = "INFRASTRUCTURE_FILE_READ_ERROR"; InfrastructureErrorCodes["FILE_WRITE_ERROR"] = "INFRASTRUCTURE_FILE_WRITE_ERROR"; InfrastructureErrorCodes["FILE_DELETE_ERROR"] = "INFRASTRUCTURE_FILE_DELETE_ERROR"; InfrastructureErrorCodes["FILE_PERMISSION_ERROR"] = "INFRASTRUCTURE_FILE_PERMISSION_ERROR"; InfrastructureErrorCodes["FILE_SYSTEM_ERROR"] = "INFRASTRUCTURE_FILE_SYSTEM_ERROR"; InfrastructureErrorCodes["FILE_ALREADY_EXISTS"] = "INFRASTRUCTURE_FILE_ALREADY_EXISTS"; InfrastructureErrorCodes["DIRECTORY_NOT_FOUND"] = "INFRASTRUCTURE_DIRECTORY_NOT_FOUND"; InfrastructureErrorCodes["DIRECTORY_CREATE_ERROR"] = "INFRASTRUCTURE_DIRECTORY_CREATE_ERROR"; InfrastructureErrorCodes["INDEX_UPDATE_ERROR"] = "INFRASTRUCTURE_INDEX_UPDATE_ERROR"; InfrastructureErrorCodes["INITIALIZATION_ERROR"] = "INFRASTRUCTURE_INITIALIZATION_ERROR"; InfrastructureErrorCodes["CONFIGURATION_ERROR"] = "INFRASTRUCTURE_CONFIGURATION_ERROR"; InfrastructureErrorCodes["INVALID_ARGUMENT"] = "INFRASTRUCTURE_INVALID_ARGUMENT"; InfrastructureErrorCodes["PERSISTENCE_ERROR"] = "INFRASTRUCTURE_PERSISTENCE_ERROR"; InfrastructureErrorCodes["MCP_SERVER_ERROR"] = "INFRASTRUCTURE_MCP_SERVER_ERROR"; InfrastructureErrorCodes["INVALID_FILE_CONTENT"] = "INFRASTRUCTURE_INVALID_FILE_CONTENT"; InfrastructureErrorCodes["GIT_COMMAND_FAILED"] = "INFRASTRUCTURE_GIT_COMMAND_FAILED"; })(InfrastructureErrorCodes || (InfrastructureErrorCodes = {})); /** * Error for the infrastructure layer */ export class InfrastructureError extends BaseError { constructor(code, message, details) { super(code, message, details); } withMessage(newMessage) { return new InfrastructureError(this.code, newMessage, this.details); } getHttpStatusCode() { switch (this.code) { case InfrastructureErrorCodes.FILE_NOT_FOUND: case InfrastructureErrorCodes.DIRECTORY_NOT_FOUND: return 404; case InfrastructureErrorCodes.FILE_PERMISSION_ERROR: return 403; case InfrastructureErrorCodes.FILE_ALREADY_EXISTS: return 409; default: return 500; } } } /** * Factory methods for infrastructure errors */ export const InfrastructureErrors = { /** * Error for when a file is not found */ fileNotFound: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.FILE_NOT_FOUND, message, details); }, /** * Error for file read errors */ fileReadError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.FILE_READ_ERROR, message, details); }, /** * Error for file write errors */ fileWriteError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.FILE_WRITE_ERROR, message, details); }, /** * Error for file delete errors */ fileDeleteError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.FILE_DELETE_ERROR, message, details); }, /** * Error for file permission errors */ permissionDenied: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.FILE_PERMISSION_ERROR, message, details); }, /** * General file system error */ fileSystemError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.FILE_SYSTEM_ERROR, message, details); }, /** * Error for when a file already exists */ fileAlreadyExists: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.FILE_ALREADY_EXISTS, message, details); }, /** * Error for when a directory is not found */ directoryNotFound: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.DIRECTORY_NOT_FOUND, message, details); }, /** * Error for directory creation errors */ directoryCreateError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.DIRECTORY_CREATE_ERROR, message, details); }, /** * Error for index update errors */ indexUpdateError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.INDEX_UPDATE_ERROR, message, details); }, /** * Error for initialization errors */ initializationError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.INITIALIZATION_ERROR, message, details); }, /** * General MCP server error */ mcpServerError: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.MCP_SERVER_ERROR, message, details); }, /** * Error for invalid file content */ invalidFileContent: (message, details) => { return new InfrastructureError(InfrastructureErrorCodes.INVALID_FILE_CONTENT, message, details); }, /** * Error for Git command failures * @param command The Git command that failed * @param reason A description of why it failed (e.g., stderr output) * @param cause The underlying error object, if any */ gitCommandFailed: (command, reason, cause) => { return new InfrastructureError(InfrastructureErrorCodes.GIT_COMMAND_FAILED, `Git command failed: '${command}'. Reason: ${reason}`, { command, reason, cause }); }, }; //# sourceMappingURL=InfrastructureError.js.map