From ae6c38831415f9fc1de2d3dd1d4a247becbbd32f Mon Sep 17 00:00:00 2001 From: tbounsiar Date: Fri, 27 Mar 2026 13:10:24 +0100 Subject: [PATCH] fix: log warnings for malformed settings files instead of silent fallback (#486) ## Summary - `loadSettingsFile()` silently returned `{}` for **all** errors including malformed JSON, permission errors, and unexpected file content - Only `ENOENT` (file not found) should be silent since missing settings files are expected - Other errors now log a warning via the logger to help diagnose misconfigured settings (e.g. a typo in `settings.json` was previously completely invisible) ## Test plan - [x] `npm run lint` passes - [x] All settings tests pass - [x] Missing files still return `{}` silently (ENOENT path unchanged) - [x] Malformed JSON now produces a logged warning --- src/settings.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/settings.ts b/src/settings.ts index 45200aeb..0e55aa7e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -25,9 +25,14 @@ export interface ClaudeCodeSettings { } /** - * Reads and parses a JSON settings file, returning an empty object if not found or invalid + * Reads and parses a JSON settings file, returning an empty object if not found or invalid. + * Silently ignores missing files (ENOENT) but logs warnings for other errors + * (malformed JSON, permission errors, etc.) to aid debugging. */ -async function loadSettingsFile(filePath: string | null): Promise { +async function loadSettingsFile( + filePath: string | null, + logger?: { error: (...args: any[]) => void }, +): Promise { if (!filePath) { return {}; } @@ -35,7 +40,11 @@ async function loadSettingsFile(filePath: string | null): Promise { const [userSettings, projectSettings, localSettings, enterpriseSettings] = await Promise.all([ - loadSettingsFile(this.getUserSettingsPath()), - loadSettingsFile(this.getProjectSettingsPath()), - loadSettingsFile(this.getLocalSettingsPath()), - loadSettingsFile(getManagedSettingsPath()), + loadSettingsFile(this.getUserSettingsPath(), this.logger), + loadSettingsFile(this.getProjectSettingsPath(), this.logger), + loadSettingsFile(this.getLocalSettingsPath(), this.logger), + loadSettingsFile(getManagedSettingsPath(), this.logger), ]); this.userSettings = userSettings;