From d2f698eeae6b1be71fcb96bb0a45adff99bd69eb Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Tue, 18 Nov 2025 20:20:28 +0000 Subject: [PATCH] :bug: settings.json config update error handling (#1024) Currently, config file updates fail silently if there is a syntax error in workspace settings.json. This PR adds error handling for the config file update command and surfaces the error via a notification when thrown. After: https://github.com/user-attachments/assets/2e9bda4a-9842-4026-b092-40e3793fa3f1 ## Summary by CodeRabbit * **Bug Fixes** * Improved error handling for configuration updates with clearer error messages. When configuration fails, users now receive helpful guidance and can directly open settings to resolve syntax or formatting issues. Signed-off-by: Ian Bolton Signed-off-by: Cherry Picker --- vscode/src/utilities/configuration.ts | 40 ++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/vscode/src/utilities/configuration.ts b/vscode/src/utilities/configuration.ts index 1f31a5153..77bab347b 100644 --- a/vscode/src/utilities/configuration.ts +++ b/vscode/src/utilities/configuration.ts @@ -18,7 +18,45 @@ async function updateConfigValue( value: T | undefined, scope: vscode.ConfigurationTarget = vscode.ConfigurationTarget.Workspace, ): Promise { - await vscode.workspace.getConfiguration(EXTENSION_NAME).update(key, value, scope); + try { + await vscode.workspace.getConfiguration(EXTENSION_NAME).update(key, value, scope); + } catch (error) { + // Log the error for debugging + console.error(`Failed to update configuration key "${key}":`, error); + + let errorMessage = `Failed to update setting "${key}": `; + + if (error instanceof Error) { + if (error.message.includes("Unable to write")) { + errorMessage += "Your settings.json may contain syntax errors."; + } else { + errorMessage += error.message; + } + } else { + errorMessage += String(error); + } + + // Show error notification with option to open settings + vscode.window.showErrorMessage(errorMessage, "Open Settings").then(async (action) => { + if (action === "Open Settings") { + await vscode.commands.executeCommand("workbench.action.openWorkspaceSettingsFile"); + // Show helpful tip about fixing JSON errors + vscode.window + .showInformationMessage( + 'Tip: Use "Format Document" (Shift+Alt+F) to help identify JSON syntax errors.', + "Format Now", + ) + .then((formatAction) => { + if (formatAction === "Format Now") { + vscode.commands.executeCommand("editor.action.formatDocument"); + } + }); + } + }); + + // Re-throw the error so callers can handle it if needed + throw error; + } } export const getConfigAnalyzerPath = (): string => getConfigValue("analyzerPath") || "";