Added an error parameter to PrintUtils#error to allow logging of an accompany Error obj

This commit is contained in:
Kallum Jones 2022-08-03 17:18:21 +01:00
parent 6b700d465b
commit fc18d70e49
No known key found for this signature in database
GPG Key ID: D7F4589C4D7F81A9
3 changed files with 12 additions and 3 deletions

View File

@ -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)
})

View File

@ -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);
}
}
}

View File

@ -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)
}
}
}
}