From 6995cb447d719d272fb056ccbf926dd984d50091 Mon Sep 17 00:00:00 2001 From: cgombauld Date: Thu, 26 Feb 2026 10:14:38 +0100 Subject: [PATCH] feat(cli): add error logging --- i18n/arabic.js | 8 ++++++++ i18n/english.js | 8 ++++++++ i18n/french.js | 8 ++++++++ i18n/turkish.js | 8 ++++++++ src/commands/scanner.js | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/i18n/arabic.js b/i18n/arabic.js index f994fedf..1f9390ac 100644 --- a/i18n/arabic.js +++ b/i18n/arabic.js @@ -9,6 +9,14 @@ const cli = { http_server_started: "تم تشغيل خادم HTTP على:", missingEnv: tS`متغير البيئة ${0} مفقود!`, stat: tS`${0} ${1} في ${2}`, + error: { + name: tS`اسم ${0}: ${1}`, + message: tS`الرسالة: ${0}`, + phase: tS`حدث الخطأ أثناء مرحلة ${0}`, + statusCode: tS`رمز حالة HTTP: ${0}`, + executionTime: tS`حدث الخطأ في ${0} أثناء التنفيذ`, + stack: tS`المكدس: ${0}` + }, commands: { option_depth: "أقصى عمق للتبعيات لجلبه", option_output: "اسم ملف JSON الناتج", diff --git a/i18n/english.js b/i18n/english.js index 1e4f986a..9ad46300 100644 --- a/i18n/english.js +++ b/i18n/english.js @@ -11,6 +11,14 @@ const cli = { http_server_started: "HTTP Server started on:", missingEnv: tS`Environment variable ${0} is missing!`, stat: tS`${0} ${1} in ${2}`, + error: { + name: tS`${0} name: ${1}`, + message: tS`Message: ${0}`, + phase: tS`The error occured during the ${0} phase`, + statusCode: tS`HTTP Status Code: ${0}`, + executionTime: tS`The error occured at ${0} during the execution`, + stack: tS`Stack: ${0}` + }, commands: { option_depth: "Maximum dependencies depth to fetch", option_output: "Json file output name", diff --git a/i18n/french.js b/i18n/french.js index 93e25185..0729487a 100644 --- a/i18n/french.js +++ b/i18n/french.js @@ -11,6 +11,14 @@ const cli = { http_server_started: "Serveur HTTP démarré sur :", missingEnv: tS`La variable d'environnement ${0} est manquante!`, stat: tS`${0} ${1} en ${2}`, + error: { + name: tS`Nom ${0}: ${1}`, + message: tS`Message: ${0}`, + phase: tS`L'erreur s'est produite pendant la phase ${0}`, + statusCode: tS`Code statut HTTP: ${0}`, + executionTime: tS`L'erreur s'est produite à ${0} pendant l'exécution`, + stack: tS`Stack: ${0}` + }, commands: { option_depth: "Niveau de profondeur de dépendances maximum à aller chercher", option_output: "Nom de sortie du fichier json", diff --git a/i18n/turkish.js b/i18n/turkish.js index a9f0303e..523c038c 100644 --- a/i18n/turkish.js +++ b/i18n/turkish.js @@ -11,6 +11,14 @@ const cli = { http_server_started: "HTTP Sunucusu başlatıldı:", missingEnv: tS`${0} ortam değişkeni eksik!`, stat: tS`${0} ${1} içinde ${2}`, + error: { + name: tS`${0} adı: ${1}`, + message: tS`Mesaj: ${0}`, + phase: tS`Hata ${0} aşamasında meydana geldi`, + statusCode: tS`HTTP Durum Kodu: ${0}`, + executionTime: tS`Hata yürütme sırasında ${0} tarihinde meydana geldi`, + stack: tS`Yığın: ${0}` + }, commands: { option_depth: "Getirilecek maksimum bağımlılık derinliği", option_output: "JSON dosyası çıktı adı", diff --git a/src/commands/scanner.js b/src/commands/scanner.js index c908b6bd..0f8db84a 100644 --- a/src/commands/scanner.js +++ b/src/commands/scanner.js @@ -200,6 +200,46 @@ function initLogger(spec, verbose = true) { startSpinners(); }); + logger.on("error", (error, phase) => { + stopSpinners(); + + console.log(kleur.bold.white( + i18n.getTokenSync("cli.error.name", + kleur.red().bold("error"), + error.name + ))); + + if (error.message) { + console.log(i18n.getTokenSync("cli.error.message", + error.message + )); + } + + if (phase) { + console.log(i18n.getTokenSync("cli.error.phase", + phase + )); + } + + if (error.statusCode) { + console.log(i18n.getTokenSync("cli.error.statusCode", + error.statusCode + )); + } + + console.log(i18n.getTokenSync("cli.error.executionTime", + kleur.cyan().bold(formatMs(error.executionTime)) + )); + + if (error.stack) { + console.log(i18n.getTokenSync("cli.error.stack", + error.stack + )); + } + + startSpinners(); + }); + return logger; }