UNPKG

snes-disassembler

Version:

A Super Nintendo (SNES) ROM disassembler for 65816 assembly

89 lines 2.38 kB
"use strict"; /** * Error Handler Module * * Centralized error handling for the SNES disassembler */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorHandler = void 0; var ErrorType; (function (ErrorType) { ErrorType["PARSING_ERROR"] = "PARSING_ERROR"; ErrorType["VALIDATION_ERROR"] = "VALIDATION_ERROR"; ErrorType["IO_ERROR"] = "IO_ERROR"; ErrorType["ANALYSIS_ERROR"] = "ANALYSIS_ERROR"; ErrorType["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR"; })(ErrorType || (ErrorType = {})); class ErrorHandler { constructor() { this.errors = []; } /** * Set error callback for custom error handling */ setErrorCallback(callback) { this.errorCallback = callback; } /** * Handle an error */ handleError(type, message, context, recoverable = true) { const error = { type, message, context, timestamp: new Date(), recoverable }; this.errors.push(error); if (this.errorCallback) { this.errorCallback(error); } else { // Default error handling console.error(`[${type}] ${message}`, context); } if (!recoverable) { throw new Error(`Fatal error: ${message}`); } } /** * Get all recorded errors */ getErrors() { return [...this.errors]; } /** * Clear error history */ clearErrors() { this.errors = []; } /** * Get errors of a specific type */ getErrorsByType(type) { return this.errors.filter(error => error.type === type); } /** * Check if there are any fatal errors */ hasFatalErrors() { return this.errors.some(error => !error.recoverable); } /** * Generate error summary */ getErrorSummary() { const errorCounts = new Map(); for (const error of this.errors) { errorCounts.set(error.type, (errorCounts.get(error.type) || 0) + 1); } const summary = Array.from(errorCounts.entries()) .map(([type, count]) => `${type}: ${count}`) .join(', '); return `Total errors: ${this.errors.length} (${summary})`; } } exports.ErrorHandler = ErrorHandler; //# sourceMappingURL=error-handler.js.map