Skip to content

Commit ab57b73

Browse files
committed
address comments
1 parent 4f0c673 commit ab57b73

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

src/common/telemetry/errorClassifier.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CancellationError } from 'vscode';
2+
import { RpcTimeoutError } from '../../managers/common/nativePythonFinder';
23

34
export type DiscoveryErrorType =
45
| 'spawn_timeout'
@@ -17,6 +18,10 @@ export function classifyError(ex: unknown): DiscoveryErrorType {
1718
return 'canceled';
1819
}
1920

21+
if (ex instanceof RpcTimeoutError) {
22+
return 'spawn_timeout';
23+
}
24+
2025
if (!(ex instanceof Error)) {
2126
return 'unknown';
2227
}

src/extension.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,14 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
542542
);
543543

544544
sendTelemetryEvent(EventNames.EXTENSION_MANAGER_REGISTRATION_DURATION, start.elapsedTime);
545-
await terminalManager.initialize(api);
546-
sendManagerSelectionTelemetry(projectManager);
547-
await sendProjectStructureTelemetry(projectManager, envManagers);
545+
546+
try {
547+
await terminalManager.initialize(api);
548+
sendManagerSelectionTelemetry(projectManager);
549+
await sendProjectStructureTelemetry(projectManager, envManagers);
550+
} catch (postInitError) {
551+
traceError('Post-initialization tasks failed:', postInitError);
552+
}
548553
} catch (error) {
549554
traceError('Failed to initialize environment managers:', error);
550555
sendTelemetryEvent(
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import assert from 'node:assert';
2+
import { CancellationError } from 'vscode';
3+
import { classifyError } from '../../../common/telemetry/errorClassifier';
4+
import { RpcTimeoutError } from '../../../managers/common/nativePythonFinder';
5+
6+
suite('Error Classifier', () => {
7+
suite('classifyError', () => {
8+
test('should classify CancellationError as canceled', () => {
9+
assert.strictEqual(classifyError(new CancellationError()), 'canceled');
10+
});
11+
12+
test('should classify RpcTimeoutError as spawn_timeout', () => {
13+
assert.strictEqual(classifyError(new RpcTimeoutError('resolve', 30000)), 'spawn_timeout');
14+
});
15+
16+
test('should classify non-Error values as unknown', () => {
17+
assert.strictEqual(classifyError('string error'), 'unknown');
18+
assert.strictEqual(classifyError(42), 'unknown');
19+
assert.strictEqual(classifyError(null), 'unknown');
20+
assert.strictEqual(classifyError(undefined), 'unknown');
21+
});
22+
23+
test('should classify ENOENT errors as spawn_enoent', () => {
24+
const err = new Error('spawn python ENOENT') as NodeJS.ErrnoException;
25+
err.code = 'ENOENT';
26+
assert.strictEqual(classifyError(err), 'spawn_enoent');
27+
});
28+
29+
test('should classify EACCES errors as permission_denied', () => {
30+
const err = new Error('permission denied') as NodeJS.ErrnoException;
31+
err.code = 'EACCES';
32+
assert.strictEqual(classifyError(err), 'permission_denied');
33+
});
34+
35+
test('should classify EPERM errors as permission_denied', () => {
36+
const err = new Error('operation not permitted') as NodeJS.ErrnoException;
37+
err.code = 'EPERM';
38+
assert.strictEqual(classifyError(err), 'permission_denied');
39+
});
40+
41+
test('should classify timeout messages as spawn_timeout', () => {
42+
assert.strictEqual(classifyError(new Error('Request timed out')), 'spawn_timeout');
43+
assert.strictEqual(classifyError(new Error('Connection timeout')), 'spawn_timeout');
44+
});
45+
46+
test('should classify parse errors as parse_error', () => {
47+
assert.strictEqual(classifyError(new Error('Failed to parse output')), 'parse_error');
48+
assert.strictEqual(classifyError(new Error('Unexpected token < in JSON')), 'parse_error');
49+
assert.strictEqual(classifyError(new Error('Invalid JSON response')), 'parse_error');
50+
});
51+
52+
test('should classify AbortError name as canceled', () => {
53+
const err = new Error('aborted');
54+
err.name = 'AbortError';
55+
assert.strictEqual(classifyError(err), 'canceled');
56+
});
57+
58+
test('should classify error with CancellationError name as canceled', () => {
59+
const err = new Error('cancelled');
60+
err.name = 'CancellationError';
61+
assert.strictEqual(classifyError(err), 'canceled');
62+
});
63+
64+
test('should classify unrecognized errors as unknown', () => {
65+
assert.strictEqual(classifyError(new Error('something went wrong')), 'unknown');
66+
});
67+
});
68+
});

0 commit comments

Comments
 (0)