Make error handling clearer in Mods

This commit is contained in:
Kallum Jones 2022-08-03 17:30:47 +01:00
parent fc18d70e49
commit 2b5d2a3643
No known key found for this signature in database
GPG Key ID: D7F4589C4D7F81A9
2 changed files with 20 additions and 4 deletions

View File

@ -28,7 +28,9 @@ export default class Mods {
if (e instanceof ModNotFoundError) { if (e instanceof ModNotFoundError) {
PrintUtils.info(`Mod not found on ${source.getName()}`); PrintUtils.info(`Mod not found on ${source.getName()}`);
} else { } else {
throw e; PrintUtils.error(`An error occurred searching for ${mod} on ${source.getName()}. Skipping ${source.getName()}`, e)
// Try the next source
continue;
} }
} }
@ -39,7 +41,8 @@ export default class Mods {
await source.install(id); await source.install(id);
PrintUtils.success(`Successfully installed ${mod}`); PrintUtils.success(`Successfully installed ${mod}`);
} catch (e) { } catch (e) {
PrintUtils.error(`An error occurred while downloading ${mod} from ${source.getName()}`, e); // Log the error, and continue to next source
PrintUtils.error(e);
} }
} }
} }

View File

@ -52,9 +52,22 @@ export default class PrintUtils {
console.log(chalk.greenBright(print)); console.log(chalk.greenBright(print));
} }
static error(print: string, err?: Error) { static error(print: string | Error, err?: Error) {
console.log(chalk.redBright(print)); // If provided an error
if (print instanceof Error) {
// Output the error message
console.log(chalk.redBright(print.message));
// If no accompanying error to log was passed, log this one
if (err == null) {
err = print;
}
} else {
// If a string is provided, output to user
console.log(chalk.redBright(print));
}
// If there is an error to log, log it
if (err instanceof Error) { if (err instanceof Error) {
if (ModManager.logger != null) { if (ModManager.logger != null) {
ModManager.logger.error(err) ModManager.logger.error(err)