From 96bbc92ae9c8aeb8f9f71f19fe5d1ca30194f6a4 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 15 Jun 2025 12:57:36 +0200 Subject: [PATCH] chore: improve error reporting when config.json exists with invalid json --- src/index.ts | 7 ++++++- src/services/configWatcherService.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 80adc252..d4b0f810 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,14 @@ // First, init config. import { config, loadConfig } from "@/src/services/configService"; +import fs from "fs"; try { loadConfig(); } catch (e) { - console.log("ERROR: Failed to load config.json. You can copy config.json.example to create your config.json."); + if (fs.existsSync("config.json")) { + console.log("Failed to load config.json: " + (e as Error).message); + } else { + console.log("Failed to load config.json. You can copy config.json.example to create your config.json."); + } process.exit(1); } diff --git a/src/services/configWatcherService.ts b/src/services/configWatcherService.ts index 77c56d9a..88a5acdc 100644 --- a/src/services/configWatcherService.ts +++ b/src/services/configWatcherService.ts @@ -13,7 +13,7 @@ fs.watchFile(configPath, () => { try { loadConfig(); } catch (e) { - logger.error("Failed to reload config.json. Did you delete it?! Execution cannot continue."); + logger.error("FATAL ERROR: Config failed to be reloaded: " + (e as Error).message); process.exit(1); } validateConfig();