UNPKG

mem100x

Version:

⚡ The FASTEST MCP memory server ever built - 66k+ entities/sec with intelligent context detection

273 lines 8.77 kB
"use strict"; /** * Custom error classes for better error handling and debugging * Provides structured errors with context for different failure scenarios */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolExecutionError = exports.ToolNotFoundError = exports.MCPError = exports.RestoreFailedError = exports.BackupFailedError = exports.BackupError = exports.CacheCapacityError = exports.CacheError = exports.InvalidConfigError = exports.MissingConfigError = exports.ConfigurationError = exports.InvalidInputError = exports.ValidationError = exports.ContextDetectionError = exports.InvalidContextError = exports.ContextError = exports.TransactionAlreadyActiveError = exports.NoActiveTransactionError = exports.TransactionError = exports.InvalidRelationError = exports.DuplicateEntityError = exports.EntityNotFoundError = exports.DatabaseError = exports.Mem100xError = void 0; exports.isMem100xError = isMem100xError; exports.createErrorResponse = createErrorResponse; /** * Base error class for all Mem100x errors */ class Mem100xError extends Error { timestamp; context; constructor(message, context) { super(message); this.name = this.constructor.name; this.timestamp = new Date(); this.context = context; // Maintains proper stack trace for where error was thrown if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } } toJSON() { return { name: this.name, message: this.message, timestamp: this.timestamp.toISOString(), context: this.context, stack: this.stack }; } } exports.Mem100xError = Mem100xError; /** * Database-related errors */ class DatabaseError extends Mem100xError { constructor(message, context) { super(message, context); } } exports.DatabaseError = DatabaseError; class EntityNotFoundError extends DatabaseError { entityName; constructor(entityName) { super(`Entity not found: ${entityName}`, { entityName }); this.entityName = entityName; } } exports.EntityNotFoundError = EntityNotFoundError; class DuplicateEntityError extends DatabaseError { entityName; constructor(entityName) { super(`Entity already exists: ${entityName}`, { entityName }); this.entityName = entityName; } } exports.DuplicateEntityError = DuplicateEntityError; class InvalidRelationError extends DatabaseError { from; to; relationType; constructor(from, to, relationType, reason) { super(`Invalid relation: ${reason}`, { from, to, relationType }); this.from = from; this.to = to; this.relationType = relationType; } } exports.InvalidRelationError = InvalidRelationError; /** * Transaction-related errors */ class TransactionError extends Mem100xError { constructor(message, context) { super(message, context); } } exports.TransactionError = TransactionError; class NoActiveTransactionError extends TransactionError { constructor(operation) { super(`No active transaction for operation: ${operation}`, { operation }); } } exports.NoActiveTransactionError = NoActiveTransactionError; class TransactionAlreadyActiveError extends TransactionError { constructor(transactionId) { super('A transaction is already active', { transactionId }); } } exports.TransactionAlreadyActiveError = TransactionAlreadyActiveError; /** * Context-related errors */ class ContextError extends Mem100xError { constructor(message, context) { super(message, context); } } exports.ContextError = ContextError; class InvalidContextError extends ContextError { invalidContext; validContexts; constructor(invalidContext, validContexts) { super(`Invalid context '${invalidContext}'. Valid contexts: ${validContexts.join(', ')}`, { invalidContext, validContexts }); this.invalidContext = invalidContext; this.validContexts = validContexts; } } exports.InvalidContextError = InvalidContextError; class ContextDetectionError extends ContextError { constructor(message, context) { super(`Context detection failed: ${message}`, context); } } exports.ContextDetectionError = ContextDetectionError; /** * Validation errors */ class ValidationError extends Mem100xError { field; value; constructor(message, field, value) { super(message, { field, value }); this.field = field; this.value = value; } } exports.ValidationError = ValidationError; class InvalidInputError extends ValidationError { constructor(field, value, expectedType) { super(`Invalid input for field '${field}': expected ${expectedType}, got ${typeof value}`, field, value); } } exports.InvalidInputError = InvalidInputError; /** * Configuration errors */ class ConfigurationError extends Mem100xError { constructor(message, context) { super(message, context); } } exports.ConfigurationError = ConfigurationError; class MissingConfigError extends ConfigurationError { configKey; constructor(configKey) { super(`Missing required configuration: ${configKey}`, { configKey }); this.configKey = configKey; } } exports.MissingConfigError = MissingConfigError; class InvalidConfigError extends ConfigurationError { configKey; configValue; constructor(configKey, configValue, reason) { super(`Invalid configuration for '${configKey}': ${reason}`, { configKey, configValue }); this.configKey = configKey; this.configValue = configValue; } } exports.InvalidConfigError = InvalidConfigError; /** * Cache-related errors */ class CacheError extends Mem100xError { constructor(message, context) { super(message, context); } } exports.CacheError = CacheError; class CacheCapacityError extends CacheError { requestedSize; maxSize; constructor(requestedSize, maxSize) { super(`Cache capacity exceeded: requested ${requestedSize}, max ${maxSize}`, { requestedSize, maxSize }); this.requestedSize = requestedSize; this.maxSize = maxSize; } } exports.CacheCapacityError = CacheCapacityError; /** * Backup/Restore errors */ class BackupError extends Mem100xError { constructor(message, context) { super(message, context); } } exports.BackupError = BackupError; class BackupFailedError extends BackupError { backupPath; originalError; constructor(backupPath, originalError) { super(`Backup failed for path: ${backupPath}`, { backupPath, originalError: originalError?.message }); this.backupPath = backupPath; this.originalError = originalError; } } exports.BackupFailedError = BackupFailedError; class RestoreFailedError extends BackupError { restorePath; originalError; constructor(restorePath, originalError) { super(`Restore failed from path: ${restorePath}`, { restorePath, originalError: originalError?.message }); this.restorePath = restorePath; this.originalError = originalError; } } exports.RestoreFailedError = RestoreFailedError; /** * MCP Protocol errors */ class MCPError extends Mem100xError { toolName; constructor(message, toolName, context) { super(message, { ...context, toolName }); this.toolName = toolName; } } exports.MCPError = MCPError; class ToolNotFoundError extends MCPError { constructor(toolName) { super(`Tool not found: ${toolName}`, toolName); } } exports.ToolNotFoundError = ToolNotFoundError; class ToolExecutionError extends MCPError { originalError; constructor(toolName, originalError) { super(`Tool execution failed: ${toolName}`, toolName, { originalError: originalError?.message }); this.originalError = originalError; } } exports.ToolExecutionError = ToolExecutionError; /** * Helper function to determine if an error is a Mem100x error */ function isMem100xError(error) { return error instanceof Mem100xError; } /** * Helper function to create a structured error response */ function createErrorResponse(error) { if (isMem100xError(error)) { return { error: { type: error.constructor.name, message: error.message, details: error.context } }; } if (error instanceof Error) { return { error: { type: 'Error', message: error.message } }; } return { error: { type: 'UnknownError', message: String(error) } }; } //# sourceMappingURL=errors.js.map