Skip to content

Commit 631236e

Browse files
Ignore the launch.json save error when clicking run/debug codelens (#673)
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
1 parent a9da070 commit 631236e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/debugCodeLensProvider.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,15 @@ async function constructDebugConfig(mainClass: string, projectName: string, work
150150

151151
// Persist the default debug configuration only if the workspace exists.
152152
if (workspace) {
153-
// Insert the default debug configuration to the beginning of launch.json.
154-
rawConfigs.splice(0, 0, debugConfig);
155-
await launchConfigurations.update("configurations", rawConfigs, vscode.ConfigurationTarget.WorkspaceFolder);
153+
try {
154+
// Insert the default debug configuration to the beginning of launch.json.
155+
rawConfigs.splice(0, 0, debugConfig);
156+
await launchConfigurations.update("configurations", rawConfigs, vscode.ConfigurationTarget.WorkspaceFolder);
157+
} catch (error) {
158+
// When launch.json has unsaved changes before invoking the update api, it will throw the error below:
159+
// 'Unable to write into launch configuration file because the file is dirty. Please save it first and then try again.'
160+
// It's safe to ignore it because the only impact is the configuration is not saved, but you can continue to start the debugger.
161+
}
156162
}
157163
}
158164

0 commit comments

Comments
 (0)