From da0c515ccb29f1c5d5fb9569da182b12e1164bf8 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Fri, 28 Feb 2025 12:34:57 -0800 Subject: [PATCH] fix bug to return empty array when no config exists --- .../configuration/launch.json/launchJsonReader.ts | 3 ++- .../launch.json/launchJsonReader.unit.test.ts | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/extension/debugger/configuration/launch.json/launchJsonReader.ts b/src/extension/debugger/configuration/launch.json/launchJsonReader.ts index ac906613..93a25841 100644 --- a/src/extension/debugger/configuration/launch.json/launchJsonReader.ts +++ b/src/extension/debugger/configuration/launch.json/launchJsonReader.ts @@ -51,7 +51,8 @@ export function getConfigurationsFromSettings(workspace: WorkspaceFolder): Debug !Array.isArray(codeWorkspaceConfig.configurations) || codeWorkspaceConfig.configurations.length === 0 ) { - throw Error('No configurations found in launch.json or settings.json'); + traceLog('No configurations found in settings.json or launch.json.'); + return []; } traceLog('Using configuration in workspace settings.json.'); return codeWorkspaceConfig.configurations; diff --git a/src/test/unittest/configuration/launch.json/launchJsonReader.unit.test.ts b/src/test/unittest/configuration/launch.json/launchJsonReader.unit.test.ts index fc1fd45b..6fc6cef3 100644 --- a/src/test/unittest/configuration/launch.json/launchJsonReader.unit.test.ts +++ b/src/test/unittest/configuration/launch.json/launchJsonReader.unit.test.ts @@ -96,7 +96,7 @@ suite('Debugging - launchJsonReader', () => { assert.strictEqual(configurations[0].name, 'Launch Program 3'); }); - test('Should error if no configurations in settings.json', () => { + test('Should return empty array if no configurations in settings.json', () => { const workspace = typemoq.Mock.ofType(); workspace.setup((w) => w.uri).returns(() => Uri.file('/path/to/workspace')); @@ -106,11 +106,8 @@ suite('Debugging - launchJsonReader', () => { sandbox.stub(vscodeapi, 'getConfiguration').returns(mockConfig.object); - assert.throws( - () => getConfigurationsFromSettings(workspace.object), - Error, - 'No configurations found in launch.json or settings.json', - ); + const configurations = getConfigurationsFromSettings(workspace.object); + assert.strictEqual(configurations.length, 0); }); }); });