|
1 | 1 | import assert from 'node:assert'; |
2 | 2 | import { CancellationError } from 'vscode'; |
| 3 | +import * as rpc from 'vscode-jsonrpc/node'; |
| 4 | +import { BaseError } from '../../../common/errors/types'; |
3 | 5 | import { classifyError } from '../../../common/telemetry/errorClassifier'; |
4 | 6 | import { RpcTimeoutError } from '../../../managers/common/nativePythonFinder'; |
5 | 7 |
|
@@ -64,5 +66,64 @@ suite('Error Classifier', () => { |
64 | 66 | test('should classify unrecognized errors as unknown', () => { |
65 | 67 | assert.strictEqual(classifyError(new Error('something went wrong')), 'unknown'); |
66 | 68 | }); |
| 69 | + |
| 70 | + test('should classify ConnectionError as connection_error', () => { |
| 71 | + assert.strictEqual( |
| 72 | + classifyError(new rpc.ConnectionError(rpc.ConnectionErrors.Closed, 'Connection closed')), |
| 73 | + 'connection_error', |
| 74 | + ); |
| 75 | + assert.strictEqual( |
| 76 | + classifyError(new rpc.ConnectionError(rpc.ConnectionErrors.Disposed, 'Connection disposed')), |
| 77 | + 'connection_error', |
| 78 | + ); |
| 79 | + }); |
| 80 | + |
| 81 | + test('should classify ResponseError as rpc_error', () => { |
| 82 | + assert.strictEqual(classifyError(new rpc.ResponseError(-32600, 'Invalid request')), 'rpc_error'); |
| 83 | + assert.strictEqual(classifyError(new rpc.ResponseError(-32601, 'Method not found')), 'rpc_error'); |
| 84 | + }); |
| 85 | + |
| 86 | + test('should classify BaseError subclasses as already_registered', () => { |
| 87 | + // Using a concrete subclass to test (BaseError is abstract) |
| 88 | + class TestRegisteredError extends BaseError { |
| 89 | + constructor(message: string) { |
| 90 | + super('InvalidArgument', message); |
| 91 | + } |
| 92 | + } |
| 93 | + assert.strictEqual( |
| 94 | + classifyError(new TestRegisteredError('Environment manager with id test already registered')), |
| 95 | + 'already_registered', |
| 96 | + ); |
| 97 | + }); |
| 98 | + |
| 99 | + test('should classify "not found" messages as tool_not_found', () => { |
| 100 | + assert.strictEqual(classifyError(new Error('Conda not found')), 'tool_not_found'); |
| 101 | + assert.strictEqual(classifyError(new Error('Python extension not found')), 'tool_not_found'); |
| 102 | + assert.strictEqual(classifyError(new Error('Poetry executable not found')), 'tool_not_found'); |
| 103 | + }); |
| 104 | + |
| 105 | + test('should classify command execution failures as command_failed', () => { |
| 106 | + assert.strictEqual( |
| 107 | + classifyError(new Error('Failed to run "conda info --envs --json":\n some error')), |
| 108 | + 'command_failed', |
| 109 | + ); |
| 110 | + assert.strictEqual(classifyError(new Error('Failed to run poetry install')), 'command_failed'); |
| 111 | + assert.strictEqual(classifyError(new Error('Error spawning conda: ENOENT')), 'command_failed'); |
| 112 | + }); |
| 113 | + |
| 114 | + test('should classify PET process crash/restart errors as process_crash', () => { |
| 115 | + assert.strictEqual( |
| 116 | + classifyError(new Error('Python Environment Tools (PET) is currently restarting. Please try again.')), |
| 117 | + 'process_crash', |
| 118 | + ); |
| 119 | + assert.strictEqual( |
| 120 | + classifyError(new Error('Python Environment Tools (PET) failed after 3 restart attempts.')), |
| 121 | + 'process_crash', |
| 122 | + ); |
| 123 | + assert.strictEqual( |
| 124 | + classifyError(new Error('Failed to create stdio streams for PET process')), |
| 125 | + 'process_crash', |
| 126 | + ); |
| 127 | + }); |
67 | 128 | }); |
68 | 129 | }); |
0 commit comments