@notjustcoders/ioc-arise
Version:
Arise type-safe IoC containers from your code. Zero overhead, zero coupling.
178 lines • 6.57 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSystemError = exports.ValidationError = exports.GenerationError = exports.AnalysisError = exports.ConfigError = exports.IoCError = exports.ErrorSeverity = exports.IoCErrorCode = void 0;
/**
* Error codes for IoC Arise CLI
*/
var IoCErrorCode;
(function (IoCErrorCode) {
// Configuration errors (1000-1099)
IoCErrorCode["CONFIG_INVALID"] = "IOC_1000";
IoCErrorCode["CONFIG_FILE_NOT_FOUND"] = "IOC_1001";
IoCErrorCode["CONFIG_PARSE_ERROR"] = "IOC_1002";
IoCErrorCode["CONFIG_VALIDATION_ERROR"] = "IOC_1003";
// Source directory errors (1100-1199)
IoCErrorCode["SOURCE_DIR_NOT_FOUND"] = "IOC_1100";
IoCErrorCode["SOURCE_DIR_NOT_ACCESSIBLE"] = "IOC_1101";
IoCErrorCode["SOURCE_DIR_EMPTY"] = "IOC_1102";
// Analysis errors (1200-1299)
IoCErrorCode["ANALYSIS_FAILED"] = "IOC_1200";
IoCErrorCode["NO_CLASSES_FOUND"] = "IOC_1201";
IoCErrorCode["CIRCULAR_DEPENDENCY"] = "IOC_1202";
IoCErrorCode["DUPLICATE_INTERFACE_IMPLEMENTATION"] = "IOC_1203";
IoCErrorCode["DUPLICATE_ABSTRACT_CLASS_EXTENSION"] = "IOC_1204";
IoCErrorCode["INVALID_INTERFACE_PATTERN"] = "IOC_1205";
// Generation errors (1300-1399)
IoCErrorCode["GENERATION_FAILED"] = "IOC_1300";
IoCErrorCode["OUTPUT_FILE_ERROR"] = "IOC_1301";
IoCErrorCode["TEMPLATE_ERROR"] = "IOC_1302";
// Module errors (1400-1499)
IoCErrorCode["MODULE_CONFIG_INVALID"] = "IOC_1400";
IoCErrorCode["MODULE_PATTERN_INVALID"] = "IOC_1401";
IoCErrorCode["MODULE_DUPLICATE_PATTERN"] = "IOC_1402";
// File system errors (1500-1599)
IoCErrorCode["FILE_NOT_FOUND"] = "IOC_1500";
IoCErrorCode["FILE_READ_ERROR"] = "IOC_1501";
IoCErrorCode["FILE_WRITE_ERROR"] = "IOC_1502";
IoCErrorCode["PERMISSION_DENIED"] = "IOC_1503";
// Validation errors (1600-1699)
IoCErrorCode["VALIDATION_ERROR"] = "IOC_1600";
IoCErrorCode["SCHEMA_VALIDATION_ERROR"] = "IOC_1601";
IoCErrorCode["TYPE_VALIDATION_ERROR"] = "IOC_1602";
// Runtime errors (1700-1799)
IoCErrorCode["RUNTIME_ERROR"] = "IOC_1700";
IoCErrorCode["UNEXPECTED_ERROR"] = "IOC_1701";
IoCErrorCode["INITIALIZATION_ERROR"] = "IOC_1702";
// Renderer errors (1800-1899)
IoCErrorCode["RENDERER_NOT_FOUND"] = "IOC_1800";
IoCErrorCode["RENDERER_ERROR"] = "IOC_1801";
})(IoCErrorCode || (exports.IoCErrorCode = IoCErrorCode = {}));
/**
* Severity levels for errors
*/
var ErrorSeverity;
(function (ErrorSeverity) {
ErrorSeverity["LOW"] = "low";
ErrorSeverity["MEDIUM"] = "medium";
ErrorSeverity["HIGH"] = "high";
ErrorSeverity["CRITICAL"] = "critical";
})(ErrorSeverity || (exports.ErrorSeverity = ErrorSeverity = {}));
/**
* Base IoC error class with custom error codes
*/
class IoCError extends Error {
constructor(code, message, severity = ErrorSeverity.MEDIUM, context, suggestions) {
super(message);
this.name = 'IoCError';
this.code = code;
this.severity = severity;
this.context = context;
this.timestamp = new Date();
this.suggestions = suggestions;
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, IoCError);
}
}
/**
* Get a formatted error message with code and context
*/
getFormattedMessage() {
let message = `[${this.code}] ${this.message}`;
if (this.context) {
const contextParts = [];
if (this.context.filePath) {
contextParts.push(`File: ${this.context.filePath}`);
}
if (this.context.lineNumber) {
contextParts.push(`Line: ${this.context.lineNumber}`);
}
if (this.context.className) {
contextParts.push(`Class: ${this.context.className}`);
}
if (this.context.interfaceName) {
contextParts.push(`Interface: ${this.context.interfaceName}`);
}
if (this.context.moduleName) {
contextParts.push(`Module: ${this.context.moduleName}`);
}
if (contextParts.length > 0) {
message += `\n Context: ${contextParts.join(', ')}`;
}
}
if (this.suggestions && this.suggestions.length > 0) {
message += `\n Suggestions:`;
this.suggestions.forEach(suggestion => {
message += `\n • ${suggestion}`;
});
}
return message;
}
/**
* Convert error to JSON for logging or API responses
*/
toJSON() {
return {
name: this.name,
code: this.code,
message: this.message,
severity: this.severity,
context: this.context,
timestamp: this.timestamp.toISOString(),
suggestions: this.suggestions,
stack: this.stack
};
}
}
exports.IoCError = IoCError;
/**
* Configuration-specific error
*/
class ConfigError extends IoCError {
constructor(code, message, context, suggestions) {
super(code, message, ErrorSeverity.HIGH, context, suggestions);
this.name = 'ConfigError';
}
}
exports.ConfigError = ConfigError;
/**
* Analysis-specific error
*/
class AnalysisError extends IoCError {
constructor(code, message, context, suggestions) {
super(code, message, ErrorSeverity.MEDIUM, context, suggestions);
this.name = 'AnalysisError';
}
}
exports.AnalysisError = AnalysisError;
/**
* Generation-specific error
*/
class GenerationError extends IoCError {
constructor(code, message, context, suggestions) {
super(code, message, ErrorSeverity.HIGH, context, suggestions);
this.name = 'GenerationError';
}
}
exports.GenerationError = GenerationError;
/**
* Validation-specific error
*/
class ValidationError extends IoCError {
constructor(code, message, context, suggestions) {
super(code, message, ErrorSeverity.MEDIUM, context, suggestions);
this.name = 'ValidationError';
}
}
exports.ValidationError = ValidationError;
/**
* File system-specific error
*/
class FileSystemError extends IoCError {
constructor(code, message, context, suggestions) {
super(code, message, ErrorSeverity.HIGH, context, suggestions);
this.name = 'FileSystemError';
}
}
exports.FileSystemError = FileSystemError;
//# sourceMappingURL=IoCError.js.map