Skip to content

Commit ff04c97

Browse files
authored
Merge pull request #39 from exasol-labs/ja.aggregate-error-fix
Unpack AggregateError inner errors in formatError for better diagnostics
2 parents 81d5600 + bd67ba5 commit ff04c97

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/connectionTypes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export type TlsMode = 'off' | 'fingerprint' | 'full';
1111
* instead of Error instances.
1212
*/
1313
export function formatError(error: unknown): string {
14+
if (error instanceof AggregateError && error.errors?.length) {
15+
const inner = error.errors.map(e => formatError(e)).join('; ');
16+
return error.message ? `${error.message}: ${inner}` : inner;
17+
}
1418
if (error instanceof Error) {
1519
// Some errors (e.g. from ws/Node.js net) have an empty message but a useful .code
1620
const code = (error as any).code;

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { SessionManager } from './sessionManager';
1515
import { ObjectActions } from './objectActions';
1616
import { ObjectSearchProvider } from './providers/objectSearchProvider';
1717
import { findStatementAtCursor, splitIntoStatements } from './utils';
18+
import { formatError } from './connectionTypes';
1819

1920
// Create output channel for logging
2021
let outputChannel: vscode.OutputChannel;
@@ -616,7 +617,7 @@ async function executeQuery(
616617
}
617618

618619
} catch (error) {
619-
const errorMsg = String(error);
620+
const errorMsg = formatError(error);
620621

621622
if (statements.length > 1) {
622623
output.appendLine(` ❌ Query ${queryNum} failed: ${errorMsg}`);
@@ -843,7 +844,7 @@ async function executeStatement(
843844
}
844845
);
845846
} catch (error) {
846-
const errorMsg = String(error);
847+
const errorMsg = formatError(error);
847848
output.appendLine(`❌ Query failed: ${errorMsg}`);
848849

849850
// Show error in results panel

src/panels/connectionPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { ConnectionManager, ExasolConnection, FingerprintRequiredError, FingerprintMismatchError, normalizeFingerprint, extractFingerprintError, TlsMode } from '../connectionManager';
2+
import { ConnectionManager, ExasolConnection, FingerprintRequiredError, FingerprintMismatchError, normalizeFingerprint, extractFingerprintError, TlsMode, formatError } from '../connectionManager';
33

44
export class ConnectionPanel {
55
public static currentPanel: ConnectionPanel | undefined;
@@ -169,7 +169,7 @@ export class ConnectionPanel {
169169
return;
170170
}
171171

172-
const errorMsg = String(error);
172+
const errorMsg = formatError(error);
173173
this.outputChannel.appendLine(`❌ Connection test failed: ${errorMsg}`);
174174
this._panel.webview.postMessage({ command: 'error', error: errorMsg });
175175
}

src/test/unit/tlsValidation.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ suite('formatError', () => {
100100
test('handles numbers', () => {
101101
assert.strictEqual(formatError(42), '42');
102102
});
103+
104+
test('unpacks AggregateError inner errors', () => {
105+
const inner1 = new Error('connect ECONNREFUSED 10.0.0.1:8563');
106+
const inner2 = new Error('connect ETIMEDOUT 10.0.0.2:8563');
107+
const agg = new AggregateError([inner1, inner2], 'All connection attempts failed');
108+
assert.strictEqual(
109+
formatError(agg),
110+
'All connection attempts failed: connect ECONNREFUSED 10.0.0.1:8563; connect ETIMEDOUT 10.0.0.2:8563'
111+
);
112+
});
113+
114+
test('unpacks AggregateError with no message', () => {
115+
const inner = new Error('ECONNREFUSED');
116+
const agg = new AggregateError([inner]);
117+
assert.strictEqual(formatError(agg), 'ECONNREFUSED');
118+
});
103119
});
104120

105121
suite('FingerprintRequiredError', () => {

0 commit comments

Comments
 (0)