@typecad/kicad-symbols
Version:
Intelligent fuzzy search for KiCad symbols with CLI interface
54 lines • 1.72 kB
JavaScript
import { ErrorHandler } from './ErrorHandler.js';
/**
* Class for handling global unhandled exceptions and rejections
*/
export class GlobalErrorHandler {
static isInitialized = false;
/**
* Initializes the global error handler
*/
static initialize() {
if (this.isInitialized) {
return;
}
// Handle uncaught exceptions
process.on('uncaughtException', (error) => {
this.handleUncaughtException(error);
});
// Handle unhandled rejections
process.on('unhandledRejection', (reason) => {
this.handleUnhandledRejection(reason);
});
this.isInitialized = true;
}
/**
* Handles an uncaught exception
* @param error - The uncaught exception
*/
static handleUncaughtException(error) {
// Use ErrorHandler to get a user-friendly error message
const errorMessage = ErrorHandler.handleError(error);
console.error(`\nFatal error: ${errorMessage}`);
// Exit with error code
process.exit(1);
}
/**
* Handles an unhandled rejection
* @param reason - The reason for the rejection
*/
static handleUnhandledRejection(reason) {
let error;
if (reason instanceof Error) {
error = reason;
}
else {
error = new Error(`Unhandled rejection: ${String(reason)}`);
}
// Use ErrorHandler to get a user-friendly error message
const errorMessage = ErrorHandler.handleError(error);
console.error(`\nFatal error: ${errorMessage}`);
// Exit with error code
process.exit(1);
}
}
//# sourceMappingURL=GlobalErrorHandler.js.map