From dc1a9ca4d2c80a3a820f80775cec8c5b17cf0b60 Mon Sep 17 00:00:00 2001 From: Guillaume Brioudes Date: Sun, 1 Dec 2024 19:06:59 +0100 Subject: [PATCH] feat: error message --- app.js | 9 +++++++++ core/models/config.js | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 16efde0b..4ef93cfc 100755 --- a/app.js +++ b/app.js @@ -193,3 +193,12 @@ function setConfigFileToRun(projectName) { Config.configFilePath = Config.defaultConfigPath; } } + +process.on('uncaughtException', (err) => { + console.error(['\x1b[31m', 'Err.', '\x1b[0m'].join(''), err.message); + process.exit(1); +}); +process.on('unhandledRejection', (err) => { + console.error(['\x1b[31m', 'Err.', '\x1b[0m'].join(''), err.message); + process.exit(1); +}); diff --git a/core/models/config.js b/core/models/config.js index f0e03d31..afca775c 100644 --- a/core/models/config.js +++ b/core/models/config.js @@ -367,7 +367,7 @@ class Config { static get(configFilePath) { if (configFilePath === undefined || fs.existsSync(configFilePath) === false) { - throw new Error('Can not find config file.'); + throw new Error(`Can not find config file from ${configFilePath}.`); } const fileContent = fs.readFileSync(configFilePath, 'utf8'); @@ -390,7 +390,7 @@ class Config { .flatMap((detail) => [detail.message, detail.context.message]) .join(', '); - throw new Error(`Config schema validation failed: ${details}`); + throw new Error(`Config file ${configFilePath} contains errors :\n${details}`); } return new Config(opts);