refactor: add typed query failure signals
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
mapFallbackDispatchError,
|
||||
toDispatchFailure,
|
||||
} from './query-dispatch-error-mapper.js';
|
||||
import { GSDToolsError } from '../gsd-tools-error.js';
|
||||
|
||||
describe('query dispatch error mapper', () => {
|
||||
it('maps native timeout errors', () => {
|
||||
@@ -24,6 +25,18 @@ describe('query dispatch error mapper', () => {
|
||||
expect(err.details).toMatchObject({ command: 'state.json', args: [] });
|
||||
});
|
||||
|
||||
it('maps typed timeout classification from GSDToolsError', () => {
|
||||
const err = mapNativeDispatchError(
|
||||
new GSDToolsError('timeout', 'state', ['load'], null, '', {
|
||||
classification: { kind: 'timeout', timeoutMs: 1234 },
|
||||
}),
|
||||
'state.load',
|
||||
[],
|
||||
);
|
||||
expect(err.kind).toBe('native_timeout');
|
||||
expect(err.details).toMatchObject({ timeout_ms: 1234 });
|
||||
});
|
||||
|
||||
it('maps fallback errors', () => {
|
||||
const err = mapFallbackDispatchError(new Error('spawn ENOENT'), 'state', ['load']);
|
||||
expect(err.kind).toBe('fallback_failure');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { QueryDispatchError, QueryDispatchResult } from './query-dispatch-contract.js';
|
||||
import { errorMessage, isTimeoutMessage, parseTimeoutMs } from '../query-failure-classification.js';
|
||||
import { toFailureSignal } from '../query-failure-classification.js';
|
||||
import { fallbackFailureError, nativeFailureError, nativeTimeoutError } from './query-error-taxonomy.js';
|
||||
import { dispatchFailure } from './query-dispatch-result-builder.js';
|
||||
|
||||
@@ -11,14 +11,14 @@ export function toDispatchFailure(
|
||||
}
|
||||
|
||||
export function mapNativeDispatchError(error: unknown, command: string, args: string[]): QueryDispatchError {
|
||||
const message = errorMessage(error);
|
||||
if (isTimeoutMessage(message)) {
|
||||
return nativeTimeoutError({ message, command, args, timeoutMs: parseTimeoutMs(message) });
|
||||
const signal = toFailureSignal(error);
|
||||
if (signal.kind === 'timeout') {
|
||||
return nativeTimeoutError({ message: signal.message, command, args, timeoutMs: signal.timeoutMs });
|
||||
}
|
||||
return nativeFailureError({ message, command, args });
|
||||
return nativeFailureError({ message: signal.message, command, args });
|
||||
}
|
||||
|
||||
export function mapFallbackDispatchError(error: unknown, command: string, args: string[]): QueryDispatchError {
|
||||
const message = errorMessage(error);
|
||||
return fallbackFailureError({ message, command, args, backend: 'cjs' });
|
||||
const signal = toFailureSignal(error);
|
||||
return fallbackFailureError({ message: signal.message, command, args, backend: 'cjs' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user