Skip to content

Commit fdddaf9

Browse files
Additional graceful handling for pixi (microsoft#23942)
In addition to first PR microsoft#23937 I've been able to repro aggressive errors of ``` 2024-08-12 13:59:21.087 [error] [Error: spawn pixi ENOENT at ChildProcess._handle.onexit (node:internal/child_process:286:19) at onErrorNT (node:internal/child_process:484:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] { errno: -2, code: 'ENOENT', syscall: 'spawn pixi', path: 'pixi', spawnargs: [ '--version' ] } ``` ``` 2024-08-12 13:59:20.794 [error] Reading directory to watch failed [Error: ENOENT: no such file or directory, scandir '/Users/anthonykim/Desktop/vscode-python/.pixi/envs' at Object.readdirSync (node:fs:1509:26) at t.readdirSync (node:electron/js2c/node_init:2:11418) at /Users/anthonykim/.vscode/extensions/ms-python.python-2024.13.2024080901-darwin-arm64/out/client/extension.js:2:583006 at /Users/anthonykim/.vscode/extensions/ms-python.python-2024.13.2024080901-darwin-arm64/out/client/extension.js:2:583197 at Array.map (<anonymous>) at d.initWatchers (/Users/anthonykim/.vscode/extensions/ms-python.python-2024.13.2024080901-darwin-arm64/out/client/extension.js:2:582915) at async d.ensureWatchersReady (/Users/anthonykim/.vscode/extensions/ms-python.python-2024.13.2024080901-darwin-arm64/out/client/extension.js:2:539326)] { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/Users/anthonykim/Desktop/vscode-python/.pixi/envs' } ``` even when I dont have pixi in my workspace. Changing the log level on this and adding more wraps around that should give necessary hint/message when needed without crashing program. --------- Co-authored-by: Karthik Nadig <kanadig@microsoft.com>
1 parent 9cd6b2d commit fdddaf9

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/client/pythonEnvironments/base/locators/common/resourceBasedLocator.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { IDisposable } from '../../../../common/types';
55
import { createDeferred, Deferred } from '../../../../common/utils/async';
66
import { Disposables } from '../../../../common/utils/resourceLifecycle';
7-
import { traceError } from '../../../../logging';
7+
import { traceError, traceWarn } from '../../../../logging';
88
import { arePathsSame, isVirtualWorkspace } from '../../../common/externalDependencies';
99
import { getEnvPath } from '../../info/env';
1010
import { BasicEnvInfo, IPythonEnvsIterator, Locator, PythonLocatorQuery } from '../../locator';
@@ -36,7 +36,11 @@ export abstract class LazyResourceBasedLocator extends Locator<BasicEnvInfo> imp
3636
protected async activate(): Promise<void> {
3737
await this.ensureResourcesReady();
3838
// There is not need to wait for the watchers to get started.
39-
this.ensureWatchersReady().ignoreErrors();
39+
try {
40+
this.ensureWatchersReady();
41+
} catch (ex) {
42+
traceWarn(`Failed to ensure watchers are ready for locator ${this.constructor.name}`, ex);
43+
}
4044
}
4145

4246
public async dispose(): Promise<void> {

src/client/pythonEnvironments/base/locators/lowLevel/fsWatchingLocator.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path';
66
import { Uri } from 'vscode';
77
import { FileChangeType, watchLocationForPattern } from '../../../../common/platform/fileSystemWatcher';
88
import { sleep } from '../../../../common/utils/async';
9-
import { traceError, traceVerbose } from '../../../../logging';
9+
import { traceVerbose, traceWarn } from '../../../../logging';
1010
import { getEnvironmentDirFromPath } from '../../../common/commonUtils';
1111
import {
1212
PythonEnvStructure,
@@ -32,13 +32,13 @@ function checkDirWatchable(dirname: string): DirUnwatchableReason {
3232
names = fs.readdirSync(dirname);
3333
} catch (err) {
3434
const exception = err as NodeJS.ErrnoException;
35-
traceError('Reading directory to watch failed', exception);
35+
traceVerbose('Reading directory failed', exception);
3636
if (exception.code === 'ENOENT') {
3737
// Treat a missing directory as unwatchable since it can lead to CPU load issues:
3838
// https://github.com/microsoft/vscode-python/issues/18459
3939
return 'directory does not exist';
4040
}
41-
throw err; // re-throw
41+
return undefined;
4242
}
4343
// The limit here is an educated guess.
4444
if (names.length > 200) {
@@ -117,7 +117,7 @@ export abstract class FSWatchingLocator extends LazyResourceBasedLocator {
117117
// that might be watched due to a glob are not checked.
118118
const unwatchable = await checkDirWatchable(root);
119119
if (unwatchable) {
120-
traceError(`Dir "${root}" is not watchable (${unwatchable})`);
120+
traceWarn(`Dir "${root}" is not watchable (${unwatchable})`);
121121
return undefined;
122122
}
123123
return root;

src/client/pythonEnvironments/common/environmentManagers/pixi.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { OSType, getOSType, getUserHomeDir } from '../../../common/utils/platfor
99
import { exec, getPythonSetting, onDidChangePythonSetting, pathExists, pathExistsSync } from '../externalDependencies';
1010
import { cache } from '../../../common/utils/decorators';
1111
import { isTestExecution } from '../../../common/constants';
12-
import { traceError, traceVerbose, traceWarn } from '../../../logging';
12+
import { traceVerbose, traceWarn } from '../../../logging';
1313
import { OUTPUT_MARKER_SCRIPT } from '../../../common/process/internal/scripts';
1414

1515
export const PIXITOOLPATH_SETTING_KEY = 'pixiToolPath';
@@ -119,7 +119,7 @@ export class Pixi {
119119
yield customPixiToolPath;
120120
}
121121
} catch (ex) {
122-
traceError(`Failed to get pixi setting`, ex);
122+
traceWarn(`Failed to get pixi setting`, ex);
123123
}
124124

125125
// Check unqualified filename, in case it's on PATH.
@@ -182,7 +182,7 @@ export class Pixi {
182182
const pixiInfo: PixiInfo = JSON.parse(infoOutput.stdout);
183183
return pixiInfo;
184184
} catch (error) {
185-
traceError(`Failed to get pixi info for ${cwd}`, error);
185+
traceWarn(`Failed to get pixi info for ${cwd}`, error);
186186
return undefined;
187187
}
188188
}
@@ -199,15 +199,13 @@ export class Pixi {
199199
if (!versionOutput || !versionOutput.stdout) {
200200
return undefined;
201201
}
202-
203202
const versionParts = versionOutput.stdout.split(' ');
204203
if (versionParts.length < 2) {
205204
return undefined;
206205
}
207-
208206
return versionParts[1].trim();
209207
} catch (error) {
210-
traceError(`Failed to get pixi version`, error);
208+
traceVerbose(`Failed to get pixi version`, error);
211209
return undefined;
212210
}
213211
}

0 commit comments

Comments
 (0)