fix(telemetry): preserve driver error class and code in connection_test (#260)

Native connector test failures were flattened to `new Error(message)`,
collapsing every driver's error class to `Error` and dropping `.code` /
`.number`. connection_test telemetry could therefore not tell a SQL Server
login rejection (ELOGIN / 18456) apart from a network or TLS error, and the
only field that varied was a raw message.

Connectors now return `connectorTestFailure(error)`, which preserves the
original driver error as `cause`, and `testNativeConnection` re-throws that
cause. `scrubErrorClass` then records the real class (e.g. ConnectionError)
and `formatErrorDetail` keeps the code prefix (e.g. "ELOGIN: ..."). The
helper is the single source of truth for the failure shape across all seven
native connectors. User-facing terminal output is unchanged.
This commit is contained in:
Andrey Avtomonov 2026-06-04 14:51:14 +02:00 committed by GitHub
parent c2beaf7d55
commit ec7edf8f50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 82 additions and 18 deletions

View file

@ -303,9 +303,29 @@ export interface KtxTableListEntry {
kind: 'table' | 'view';
}
interface KtxConnectorTestResult {
export interface KtxConnectorTestResult {
success: boolean;
error?: string;
/**
* The original error thrown by the driver, preserved unflattened so the
* connection-test path can re-throw it. Keeping the real error object lets
* telemetry record the driver's actual error class (e.g. `ConnectionError`)
* and `.code` (e.g. `ELOGIN`) instead of collapsing every failure to `Error`.
*/
cause?: unknown;
}
/**
* Single source of truth for a failed connector test result. Captures the
* driver's message for display while preserving the original error as `cause`
* so callers can surface its real class and code.
*/
export function connectorTestFailure(error: unknown): KtxConnectorTestResult {
return {
success: false,
error: error instanceof Error ? error.message : String(error),
cause: error,
};
}
export interface KtxScanConnector {