Skip to content

fix: warn on malformed config.json instead of failing silently (#8) - #14

Merged
aakashrajput merged 1 commit into
KlaatAI:mainfrom
itxhadi27-cmd:fix/issue-8-config-parse-warning
Jul 18, 2026
Merged

fix: warn on malformed config.json instead of failing silently (#8)#14
aakashrajput merged 1 commit into
KlaatAI:mainfrom
itxhadi27-cmd:fix/issue-8-config-parse-warning

Conversation

@itxhadi27-cmd

Copy link
Copy Markdown
Contributor

Closes #8

loadConfig() now prints a yellow warning to stderr (matching the CLI's
existing chalk.yellow style) naming the config file path and the parse
error before falling back to defaults, instead of failing silently.

Verified manually:

  • Malformed config.json → warning printed, app still starts with defaults
  • Valid config.json → no warning, no regression

Note: PR #11 is already open referencing this issue — worth checking
for overlap before merge.

@itxhadi27-cmd

itxhadi27-cmd commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Tested manually on Windows:

  1. Malformed config.json (trailing comma) → warning printed with file path and exact parse error, app still starts normally with defaults.
  2. Valid config.json → no warning, no extra output, no regression.

Screenshot attached below.

Screenshot 2026-07-18 132713

@github-actions

Copy link
Copy Markdown
Contributor

🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call)

Issue match
The diff fully addresses issue #8. It adds the requested chalk.yellow warning to stderr via console.warn, includes the file path and parse error message, and correctly falls back to defaults without blocking startup.

Test coverage
No tests were added. A unit test for loadConfig() is missing. It should mock readFileSync to return invalid JSON and assert that console.warn is called with the expected formatted string, while verifying the function still returns DEFAULT_CONFIG.

Correctness concerns
In src/auth/credentials.ts, the catch block captures all errors from both readFileSync and JSON.parse. If readFileSync fails due to permissions (EACCES) or the path being a directory, the warning will still say "Failed to parse", which is slightly misleading. Consider separating the read and parse steps or checking err.code for precise messaging. Additionally, the PR description notes potential overlap with PR #11.

Verdict
Needs human judgment call on whether to narrow the catch block for precise error messaging, and a manual check for overlap with PR #11 before merging.

This is an automated review to help triage faster, not a gate. Nothing here blocks merging.

@aakashrajput
aakashrajput merged commit 2da8800 into KlaatAI:main Jul 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

~/.klaatai/config.json parse errors fail silently — should warn instead

2 participants