chore: improve error reporting when config.json exists with invalid json (#2166)
Some checks failed
Build / build (push) Has been cancelled
Build Docker image / docker (push) Has been cancelled

Reviewed-on: #2166
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
Sainan 2025-06-15 18:51:32 -07:00 committed by Sainan
parent 3053112428
commit c6dd8bfb81
2 changed files with 7 additions and 2 deletions

View File

@ -1,9 +1,14 @@
// First, init config. // First, init config.
import { config, loadConfig } from "@/src/services/configService"; import { config, loadConfig } from "@/src/services/configService";
import fs from "fs";
try { try {
loadConfig(); loadConfig();
} catch (e) { } 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); process.exit(1);
} }

View File

@ -13,7 +13,7 @@ fs.watchFile(configPath, () => {
try { try {
loadConfig(); loadConfig();
} catch (e) { } 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); process.exit(1);
} }
validateConfig(); validateConfig();