From 53dea5ee360f30d7461931edd7ad3a0a0b524545 Mon Sep 17 00:00:00 2001 From: Maqsood Ahmed Date: Sat, 18 Jul 2026 13:17:15 +0500 Subject: [PATCH] fix: warn on malformed config.json instead of failing silently (#8) --- src/auth/credentials.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/auth/credentials.ts b/src/auth/credentials.ts index d10d413..757a22b 100644 --- a/src/auth/credentials.ts +++ b/src/auth/credentials.ts @@ -8,6 +8,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"; import { homedir } from "os"; import { join } from "path"; +import chalk from "chalk"; const KLAATAI_DIR = join(homedir(), ".klaatai"); const CREDENTIALS_FILE = join(KLAATAI_DIR, "credentials.json"); @@ -106,7 +107,13 @@ export function loadConfig(): Config { if (!existsSync(CONFIG_FILE)) return { ...DEFAULT_CONFIG }; const raw = JSON.parse(readFileSync(CONFIG_FILE, "utf-8")); return { ...DEFAULT_CONFIG, ...raw }; - } catch { + } catch (err) { + const message = err instanceof Error ? err.message : String(err); + console.warn( + chalk.yellow( + `⚠ Failed to parse ${CONFIG_FILE}: ${message}. Falling back to default config.`, + ), + ); return { ...DEFAULT_CONFIG }; } }