2023-10-23 16:45:40 +00:00
|
|
|
import readline from "node:readline";
|
2023-10-19 17:21:17 +00:00
|
|
|
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { AsyncQueue } from "@spt-aki/utils/AsyncQueue";
|
|
|
|
import { WinstonMainLogger } from "@spt-aki/utils/logging/WinstonMainLogger";
|
2023-03-03 15:23:46 +00: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;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-10-28 20:36:48 +01: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}`);
|
2023-03-03 15:23:46 +00:00
|
|
|
if (err.stack)
|
2023-10-28 20:36:48 +01:00
|
|
|
{
|
|
|
|
this.logger.error(`\nStacktrace:\n${err.stack}`);
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00: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
|
|
|
}
|