Skip to content

Commit 041a1b7

Browse files
author
Kartik Raj
committed
Wrap proposed APIs in try...catch
1 parent ab8d3b2 commit 041a1b7

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"theme": "dark"
4747
},
4848
"engines": {
49-
"vscode": "^1.82.0-20230809"
49+
"vscode": "^1.81.0-20230809"
5050
},
5151
"enableTelemetry": false,
5252
"keywords": [

src/client/interpreter/activation/terminalEnvVarCollectionService.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from '../../common/types';
2121
import { Deferred, createDeferred } from '../../common/utils/async';
2222
import { Interpreters } from '../../common/utils/localize';
23-
import { traceDecoratorVerbose, traceVerbose } from '../../logging';
23+
import { traceDecoratorVerbose, traceVerbose, traceWarn } from '../../logging';
2424
import { IInterpreterService } from '../contracts';
2525
import { defaultShells } from './service';
2626
import { IEnvironmentActivationService } from './types';
@@ -60,8 +60,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
6060

6161
public async activate(resource: Resource): Promise<void> {
6262
if (!inTerminalEnvVarExperiment(this.experimentService)) {
63-
const workspaceFolder = this.getWorkspaceFolder(resource);
64-
this.context.getEnvironmentVariableCollection({ workspaceFolder }).clear();
63+
this.context.environmentVariableCollection.clear();
6564
await this.handleMicroVenv(resource);
6665
if (!this.registeredOnce) {
6766
this.interpreterService.onDidChangeInterpreter(
@@ -168,22 +167,26 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
168167
}
169168

170169
private async handleMicroVenv(resource: Resource) {
171-
const workspaceFolder = this.getWorkspaceFolder(resource);
172-
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
173-
if (interpreter?.envType === EnvironmentType.Venv) {
174-
const activatePath = path.join(path.dirname(interpreter.path), 'activate');
175-
if (!(await pathExists(activatePath))) {
176-
const envVarCollection = this.context.getEnvironmentVariableCollection({ workspaceFolder });
177-
const pathVarName = getSearchPathEnvVarNames()[0];
178-
envVarCollection.replace(
179-
'PATH',
180-
`${path.dirname(interpreter.path)}${path.delimiter}${process.env[pathVarName]}`,
181-
{ applyAtShellIntegration: true },
182-
);
183-
return;
170+
try {
171+
const workspaceFolder = this.getWorkspaceFolder(resource);
172+
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
173+
if (interpreter?.envType === EnvironmentType.Venv) {
174+
const activatePath = path.join(path.dirname(interpreter.path), 'activate');
175+
if (!(await pathExists(activatePath))) {
176+
const envVarCollection = this.context.getEnvironmentVariableCollection({ workspaceFolder });
177+
const pathVarName = getSearchPathEnvVarNames()[0];
178+
envVarCollection.replace(
179+
'PATH',
180+
`${path.dirname(interpreter.path)}${path.delimiter}${process.env[pathVarName]}`,
181+
{ applyAtShellIntegration: true },
182+
);
183+
return;
184+
}
184185
}
186+
this.context.getEnvironmentVariableCollection({ workspaceFolder }).clear();
187+
} catch (ex) {
188+
traceWarn(`Microvenv failed as it is using proposed API which is constantly changing`, ex);
185189
}
186-
this.context.getEnvironmentVariableCollection({ workspaceFolder }).clear();
187190
}
188191

189192
private getWorkspaceFolder(resource: Resource): WorkspaceFolder | undefined {

0 commit comments

Comments
 (0)