|
| 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