2023-10-23 16:45:40 +00:00
|
|
|
import readline from "node:readline";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
|
|
|
import { AsyncQueue } from "@spt/utils/AsyncQueue";
|
|
|
|
import { WinstonMainLogger } from "@spt/utils/logging/WinstonMainLogger";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
export class ErrorHandler {
|
2023-10-28 20:36:48 +01:00
|
|
|
private logger: ILogger;
|
2023-03-03 15:23:46 +00:00
|
|
|
private readLine: readline.Interface;
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
constructor() {
|
2023-11-07 23:27:52 -05:00
|
|
|
this.logger = new WinstonMainLogger(new AsyncQueue());
|
2023-11-15 20:35:05 -05:00
|
|
|
this.readLine = readline.createInterface({ input: process.stdin, output: process.stdout });
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
public handleCriticalError(err: Error): void {
|
2023-03-03 15:23:46 +00:00
|
|
|
this.logger.error("The application had a critical error and failed to run");
|
2023-10-28 20:36:48 +01:00
|
|
|
this.logger.error(`Exception produced: ${err.name}`);
|
2024-07-23 11:12:53 -04:00
|
|
|
if (err.stack) {
|
2023-10-28 20:36:48 +01:00
|
|
|
this.logger.error(`\nStacktrace:\n${err.stack}`);
|
|
|
|
}
|
|
|
|
|
2024-05-17 15:32:41 -04:00
|
|
|
this.readLine.question("Press Enter to close the window", (_ans) => this.readLine.close());
|
2023-10-28 20:36:48 +01:00
|
|
|
this.readLine.on("close", () => process.exit(1));
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
2023-10-28 20:36:48 +01:00
|
|
|
}
|