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