Skip to content

Commit e54fc09

Browse files
authored
Fix for UriError when using python.interpreterPath command (#18293)
1 parent 672bc1a commit e54fc09

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

news/2 Fixes/18285.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix for UriError when using python.interpreterPath command in tasks.

src/client/debugger/extension/configuration/launch.json/interpreterPathCommand.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ export class InterpreterPathCommand implements IExtensionSingleActivationService
3131
// If `launch.json` is launching this command, `args.workspaceFolder` carries the workspaceFolder
3232
// If `tasks.json` is launching this command, `args[1]` carries the workspaceFolder
3333
const workspaceFolder = 'workspaceFolder' in args ? args.workspaceFolder : args[1] ? args[1] : undefined;
34-
return this.configurationService.getSettings(workspaceFolder ? Uri.parse(workspaceFolder) : undefined)
35-
.pythonPath;
34+
let workspaceFolderUri;
35+
try {
36+
workspaceFolderUri = workspaceFolder ? Uri.parse(workspaceFolder) : undefined;
37+
} catch (ex) {
38+
workspaceFolderUri = undefined;
39+
}
40+
41+
return this.configurationService.getSettings(workspaceFolderUri).pythonPath;
3642
}
3743
}

src/test/debugger/extension/configuration/launch.json/interpreterPathCommand.unit.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,14 @@ suite('Interpreter Path Command', () => {
7474
const setting = interpreterPathCommand._getSelectedInterpreterPath(args);
7575
expect(setting).to.equal('settingValue');
7676
});
77+
78+
test('If `args[1]` is not a valid uri', async () => {
79+
const args = ['command', '${input:some_input}'];
80+
when(configService.getSettings(anything())).thenCall((arg) => {
81+
assert.deepEqual(arg, undefined);
82+
return { pythonPath: 'settingValue' } as any;
83+
});
84+
const setting = interpreterPathCommand._getSelectedInterpreterPath(args);
85+
expect(setting).to.equal('settingValue');
86+
});
7787
});

0 commit comments

Comments
 (0)