UNPKG

simple-task-master

Version:
82 lines 2.25 kB
"use strict"; /** * Custom error classes for Simple Task Master */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigurationError = exports.LockError = exports.NotFoundError = exports.FileSystemError = exports.ValidationError = exports.STMError = void 0; exports.handleGlobalError = handleGlobalError; exports.isSTMError = isSTMError; exports.hasErrorCode = hasErrorCode; /** * Base error class for STM-specific errors */ class STMError extends Error { constructor(message, cause) { super(message); this.name = this.constructor.name; if (cause) { this.cause = cause; } // Ensure proper prototype chain for instanceof checks Object.setPrototypeOf(this, new.target.prototype); } } exports.STMError = STMError; /** * Error thrown when validation fails */ class ValidationError extends STMError { code = 'VALIDATION_ERROR'; } exports.ValidationError = ValidationError; /** * Error thrown when file system operations fail */ class FileSystemError extends STMError { code = 'FILESYSTEM_ERROR'; } exports.FileSystemError = FileSystemError; /** * Error thrown when a task is not found */ class NotFoundError extends STMError { code = 'NOT_FOUND'; } exports.NotFoundError = NotFoundError; /** * Error thrown when lock operations fail */ class LockError extends STMError { code = 'LOCK_ERROR'; } exports.LockError = LockError; /** * Error thrown when configuration is invalid */ class ConfigurationError extends STMError { code = 'CONFIGURATION_ERROR'; } exports.ConfigurationError = ConfigurationError; /** * Global error handler for unhandled errors */ function handleGlobalError(error) { console.error('Fatal error:', error.message); if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') { console.error('Stack trace:', error.stack); } process.exit(1); } /** * Type guard to check if an error is an STM error */ function isSTMError(error) { return error instanceof STMError; } /** * Type guard to check if an error has a specific code */ function hasErrorCode(error, code) { return isSTMError(error) && error.code === code; } //# sourceMappingURL=errors.js.map