From fc18d70e493d45a575d2909c61b57f05a63142a1 Mon Sep 17 00:00:00 2001 From: Kallum Jones Date: Wed, 3 Aug 2022 17:18:21 +0100 Subject: [PATCH] Added an error parameter to PrintUtils#error to allow logging of an accompany Error obj --- src/mod-manager.ts | 2 +- src/mods/mods.ts | 4 +++- src/util/print_utils.ts | 9 ++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mod-manager.ts b/src/mod-manager.ts index b337b25..99547a7 100644 --- a/src/mod-manager.ts +++ b/src/mod-manager.ts @@ -47,7 +47,7 @@ export default class ModManager { static createLogger(): Logger { let logger = pino({base: {pid: undefined, hostname: undefined}}, pino.destination({dest: this.LOG_FILE})); process.on("uncaughtException", error => { - logger.error(error); + PrintUtils.error(error.message, error); setTimeout(() => process.exit(1), 1) }) diff --git a/src/mods/mods.ts b/src/mods/mods.ts index 09e21df..add928a 100644 --- a/src/mods/mods.ts +++ b/src/mods/mods.ts @@ -27,6 +27,8 @@ export default class Mods { } catch (e) { if (e instanceof ModNotFoundError) { PrintUtils.info(`Mod not found on ${source.getName()}`); + } else { + throw e; } } @@ -37,7 +39,7 @@ export default class Mods { await source.install(id); PrintUtils.success(`Successfully installed ${mod}`); } catch (e) { - PrintUtils.error(`An error occurred downloading ${mod} from ${source.getName()}`); + PrintUtils.error(`An error occurred while downloading ${mod} from ${source.getName()}`, e); } } } diff --git a/src/util/print_utils.ts b/src/util/print_utils.ts index 4bc5bdc..dfcc998 100644 --- a/src/util/print_utils.ts +++ b/src/util/print_utils.ts @@ -1,5 +1,6 @@ import chalk from "chalk"; import ora, {Ora} from "ora"; +import ModManager from "../mod-manager.js"; export default class PrintUtils { @@ -51,7 +52,13 @@ export default class PrintUtils { console.log(chalk.greenBright(print)); } - static error(print: string) { + static error(print: string, err?: Error) { console.log(chalk.redBright(print)); + + if (err instanceof Error) { + if (ModManager.logger != null) { + ModManager.logger.error(err) + } + } } } \ No newline at end of file