Skip to content

Commit 1bbca8e

Browse files
committed
address comments
1 parent b6f2479 commit 1bbca8e

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/extension.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ import { collectEnvironmentInfo, getEnvManagerAndPackageManagerConfigLevels, run
9595
import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './internal.api';
9696
import { registerSystemPythonFeatures } from './managers/builtin/main';
9797
import { SysPythonManager } from './managers/builtin/sysPythonManager';
98-
import { createNativePythonFinder, NativePythonFinder } from './managers/common/nativePythonFinder';
98+
import {
99+
createNativePythonFinder,
100+
NativePythonFinder,
101+
PetBinaryNotFoundError,
102+
} from './managers/common/nativePythonFinder';
99103
import { IDisposable } from './managers/common/types';
100104
import { registerCondaFeatures } from './managers/conda/main';
101105
import { registerPipenvFeatures } from './managers/pipenv/main';
@@ -530,21 +534,32 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
530534
traceError('Failed to start Python finder (pet):', error);
531535

532536
const errnoError = error as NodeJS.ErrnoException;
533-
// Plain Error (no .code) = binary not found by getNativePythonToolsPath.
534-
// Errno error (has .code) = spawn failed (ENOENT, EACCES, EPERM, etc.).
535-
const reason = errnoError.code ? 'spawn_failed' : 'binary_not_found';
537+
// PetBinaryNotFoundError = file missing; errno .code = OS spawn failure; anything else = unknown.
538+
const reason =
539+
error instanceof PetBinaryNotFoundError
540+
? 'binary_not_found'
541+
: errnoError.code
542+
? 'spawn_failed'
543+
: 'unknown';
536544
sendTelemetryEvent(EventNames.PET_START_FAILED, undefined, {
537545
errorCode: errnoError.code ?? 'UNKNOWN',
538546
reason,
539547
platform: process.platform,
540548
arch: process.arch,
541549
});
542550

543-
window.showErrorMessage(
544-
l10n.t(
545-
'Python Environments: Failed to start the Python finder. Some features may not work correctly. Check the Output panel for details.',
546-
),
551+
const openOutput = l10n.t('Open Output');
552+
const openSettings = l10n.t('Open Settings');
553+
const choice = await window.showErrorMessage(
554+
l10n.t('Python Environments: Failed to start the Python finder. Some features may not work correctly.'),
555+
openOutput,
556+
openSettings,
547557
);
558+
if (choice === openOutput) {
559+
outputChannel.show();
560+
} else if (choice === openSettings) {
561+
await commands.executeCommand('workbench.action.openSettings', 'python.defaultInterpreterPath');
562+
}
548563
return;
549564
}
550565

src/managers/common/nativePythonFinder.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export class ConfigureRetryState {
7676
}
7777
}
7878

79+
export class PetBinaryNotFoundError extends Error {
80+
constructor(message: string) {
81+
super(message);
82+
this.name = 'PetBinaryNotFoundError';
83+
}
84+
}
85+
7986
export async function getNativePythonToolsPath(): Promise<string> {
8087
const envsExt = getExtension(ENVS_EXTENSION_ID);
8188
if (envsExt) {
@@ -91,14 +98,14 @@ export async function getNativePythonToolsPath(): Promise<string> {
9198

9299
const python = getExtension(PYTHON_EXTENSION_ID);
93100
if (!python) {
94-
throw new Error('Python extension not found and envs extension pet binary is missing');
101+
throw new PetBinaryNotFoundError('Python extension not found and envs extension pet binary is missing');
95102
}
96103

97104
const fallbackPath = path.join(python.extensionPath, 'python-env-tools', 'bin', isWindows() ? 'pet.exe' : 'pet');
98105
const fallbackExists = await fs.pathExists(fallbackPath);
99106
traceVerbose(`[pet] Fallback path (python-ext): ${fallbackPath} — exists: ${fallbackExists}`);
100107
if (!fallbackExists) {
101-
throw new Error(`Python finder binary not found at: ${fallbackPath}`);
108+
throw new PetBinaryNotFoundError(`Python finder binary not found at: ${fallbackPath}`);
102109
}
103110
return fallbackPath;
104111
}
@@ -490,7 +497,7 @@ class NativePythonFinderImpl implements NativePythonFinder {
490497
this.proc.on('exit', (code, signal) => {
491498
this.processExited = true;
492499
const wasExpected = this.isRestarting || this.isDisposed;
493-
if (code !== 0) {
500+
if (!wasExpected && code !== 0) {
494501
this.outputChannel.error(
495502
`[pet] Python Environment Tools exited unexpectedly with code ${code}, signal ${signal}`,
496503
);

0 commit comments

Comments
 (0)