diff --git a/project/src/ErrorHandler.ts b/project/src/ErrorHandler.ts index 28f21ba2..9180cbec 100644 --- a/project/src/ErrorHandler.ts +++ b/project/src/ErrorHandler.ts @@ -7,7 +7,7 @@ import { WinstonMainLogger } from "@spt-aki/utils/logging/WinstonMainLogger"; export class ErrorHandler { - private logger:ILogger; + private logger: ILogger; private readLine: readline.Interface; constructor() @@ -19,15 +19,17 @@ export class ErrorHandler }); } - public handleCriticalError(err: any): void + public handleCriticalError(err: Error): void { this.logger.error("The application had a critical error and failed to run"); - this.logger.error(`Exception produced: ${err}`); + this.logger.error(`Exception produced: ${err.name}`); if (err.stack) - this.logger.error(`\nStacktrace:\n ${err.stack}`); - + { + this.logger.error(`\nStacktrace:\n${err.stack}`); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars this.readLine.question("Press Enter to close the window", (_ans) => this.readLine.close()); - this.readLine.on("close", () => process.exit(0)); + this.readLine.on("close", () => process.exit(1)); } -} \ No newline at end of file +} diff --git a/project/src/Program.ts b/project/src/Program.ts index b92a46e2..dcea561c 100644 --- a/project/src/Program.ts +++ b/project/src/Program.ts @@ -18,26 +18,25 @@ export class Program this.errorHandler = new ErrorHandler(); } - public start(): void + public async start(): Promise { try { Container.registerTypes(container); const childContainer = container.createChildContainer(); - childContainer.resolve("Watermark"); + const watermark = childContainer.resolve("Watermark"); + watermark.initialize(); + const preAkiModLoader = childContainer.resolve("PreAkiModLoader"); Container.registerListTypes(childContainer); - preAkiModLoader.load(childContainer) - .then(() => - { - Container.registerPostLoadTypes(container, childContainer); - childContainer.resolve("App").load(); - }).catch(rej => this.errorHandler.handleCriticalError(rej)); - + await preAkiModLoader.load(childContainer); + + Container.registerPostLoadTypes(container, childContainer); + childContainer.resolve("App").load(); } - catch (e) + catch (err: any) { - this.errorHandler.handleCriticalError(e); + this.errorHandler.handleCriticalError((err instanceof Error ? err : new Error(err))); } } } diff --git a/project/src/loaders/ModLoadOrder.ts b/project/src/loaders/ModLoadOrder.ts index 9755c1df..d9ce8056 100644 --- a/project/src/loaders/ModLoadOrder.ts +++ b/project/src/loaders/ModLoadOrder.ts @@ -1,6 +1,5 @@ import { inject, injectable } from "tsyringe"; -import { ErrorHandler } from "@spt-aki/ErrorHandler"; import { IPackageJsonData } from "@spt-aki/models/spt/mod/IPackageJsonData"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; @@ -115,10 +114,6 @@ export class ModLoadOrder if (visited.has(mod)) { - // Front: white, back: red - const errorMessage = this.localisationService.getText("modloader-cyclic_dependency"); - this.logger.error(errorMessage); - // Additional info to help debug this.logger.debug(this.localisationService.getText("modloader-checking_mod", mod)); this.logger.debug(`${this.localisationService.getText("modloader-checked")}:`); @@ -126,15 +121,12 @@ export class ModLoadOrder this.logger.debug(`${this.localisationService.getText("modloader-visited")}:`); this.logger.debug(JSON.stringify(visited, null, "\t")); - // Wait for input - const errorHandler = new ErrorHandler(); - errorHandler.handleCriticalError({errorMessage}); + throw new Error(this.localisationService.getText("modloader-cyclic_dependency")); } // Check dependencies if (!this.modsAvailable.has(mod)) { - this.logger.error(this.localisationService.getText("modloader-missing_dependency")); throw new Error(this.localisationService.getText("modloader-error_parsing_mod_load_order")); } @@ -151,10 +143,7 @@ export class ModLoadOrder { if (this.modsAvailable.get(modAfter)?.loadAfter?.includes(mod)) { - const errorMessage = this.localisationService.getText("modloader-load_order_conflict", {modOneName: mod, modTwoName: modAfter}); - this.logger.error(errorMessage); - const errorHandler = new ErrorHandler(); - errorHandler.handleCriticalError(errorMessage); + throw new Error(this.localisationService.getText("modloader-load_order_conflict", {modOneName: mod, modTwoName: modAfter})); } dependencies.add(modAfter); diff --git a/project/src/utils/Watermark.ts b/project/src/utils/Watermark.ts index 22724e1f..fb7fb068 100644 --- a/project/src/utils/Watermark.ts +++ b/project/src/utils/Watermark.ts @@ -64,6 +64,8 @@ export class WatermarkLocale export class Watermark { protected akiConfig: ICoreConfig; + protected text: string[] = []; + protected versionLabel = ""; constructor( @inject("WinstonLogger") protected logger: ILogger, @@ -73,16 +75,8 @@ export class Watermark ) { this.akiConfig = this.configServer.getConfig(ConfigTypes.CORE); - - this.initialize(); - this.setTitle(); - this.resetCursor(); - this.draw(); } - protected text: string[] = []; - protected versionLabel = ""; - public initialize(): void { const description = this.watermarkLocale.getDescription(); @@ -103,6 +97,10 @@ export class Watermark { this.text = this.text.concat([...modding]); } + + this.setTitle(); + this.resetCursor(); + this.draw(); } /**