From ebf55341a7af92eeafd656bec317d4a8cbebb99d Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Thu, 9 Jan 2025 09:27:49 +0530 Subject: [PATCH] refactor: remove templating from FATAL logs --- lib/logger/utils.ts | 5 ++++- lib/workers/global/config/parse/file.ts | 2 +- lib/workers/global/index.ts | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/logger/utils.ts b/lib/logger/utils.ts index b85f2c44de22e4..d205adeb1a42f0 100644 --- a/lib/logger/utils.ts +++ b/lib/logger/utils.ts @@ -317,7 +317,10 @@ export function validateLogLevel( }, ], }); - logger.fatal(`${logLevelToCheck} is not a valid log level. terminating...`); + logger.fatal( + { logLevel: logLevelToCheck }, + 'Invalid log level. terminating...', + ); process.exit(1); } diff --git a/lib/workers/global/config/parse/file.ts b/lib/workers/global/config/parse/file.ts index cf6ecf20c69898..ec42d187db7c95 100644 --- a/lib/workers/global/config/parse/file.ts +++ b/lib/workers/global/config/parse/file.ts @@ -59,7 +59,7 @@ export async function getConfig(env: NodeJS.ProcessEnv): Promise { config = await getParsedContent(configFile); } catch (err) { if (err instanceof SyntaxError || err instanceof TypeError) { - logger.fatal(`Could not parse config file \n ${err.stack!}`); + logger.fatal({ error: err.stack }, 'Could not parse config file'); process.exit(1); } else if (err instanceof ReferenceError) { logger.fatal( diff --git a/lib/workers/global/index.ts b/lib/workers/global/index.ts index 488be90108dfd7..173e3a02950379 100644 --- a/lib/workers/global/index.ts +++ b/lib/workers/global/index.ts @@ -221,9 +221,9 @@ export async function start(): Promise { await exportStats(config); } catch (err) /* istanbul ignore next */ { if (err.message.startsWith('Init: ')) { - logger.fatal(err.message.substring(6)); + logger.fatal({ errorMessage: err.message.substring(6) }, 'Fatal error'); } else { - logger.fatal({ err }, `Fatal error: ${String(err.message)}`); + logger.fatal({ err, errorMessage: err.message }, 'Fatal error'); } if (!config!) { // return early if we can't parse config options