refactor: reduce query error factory public surface
This commit is contained in:
@@ -3,17 +3,15 @@ import { ErrorClassification, GSDError } from './errors.js';
|
|||||||
import {
|
import {
|
||||||
createQueryNativeErrorFactory,
|
createQueryNativeErrorFactory,
|
||||||
createQueryToolsErrorFactory,
|
createQueryToolsErrorFactory,
|
||||||
failureToolsError,
|
|
||||||
timeoutToolsError,
|
|
||||||
toToolsErrorFromUnknown,
|
toToolsErrorFromUnknown,
|
||||||
} from './query-tools-error-factory.js';
|
} from './query-tools-error-factory.js';
|
||||||
|
|
||||||
describe('query tools error factory', () => {
|
describe('query tools error factory', () => {
|
||||||
it('builds timeout and failure tools errors', () => {
|
it('builds timeout and failure tools errors via seam factories', () => {
|
||||||
expect(timeoutToolsError('t', 'state', ['load'], '', 10).classification).toEqual({ kind: 'timeout', timeoutMs: 10 });
|
const toolsFactory = createQueryToolsErrorFactory();
|
||||||
expect(failureToolsError('f', 'state', ['load'], 1).classification).toEqual({ kind: 'failure' });
|
expect(toolsFactory.createTimeoutError('t', 'state', ['load'], '', 10).classification).toEqual({ kind: 'timeout', timeoutMs: 10 });
|
||||||
|
expect(toolsFactory.createFailureError('f', 'state', ['load'], 1, '').classification).toEqual({ kind: 'failure' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('maps GSDError to failure with semantic exit code', () => {
|
it('maps GSDError to failure with semantic exit code', () => {
|
||||||
const err = toToolsErrorFromUnknown('state', ['load'], new GSDError('bad', ErrorClassification.Validation));
|
const err = toToolsErrorFromUnknown('state', ['load'], new GSDError('bad', ErrorClassification.Validation));
|
||||||
expect(err.exitCode).toBe(10);
|
expect(err.exitCode).toBe(10);
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ export interface QueryNativeErrorFactory {
|
|||||||
createNativeFailureError: (message: string, command: string, args: string[], cause: unknown) => GSDToolsError;
|
createNativeFailureError: (message: string, command: string, args: string[], cause: unknown) => GSDToolsError;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function timeoutToolsError(message: string, command: string, args: string[], stderr = '', timeoutMs?: number): GSDToolsError {
|
function timeoutToolsError(message: string, command: string, args: string[], stderr = '', timeoutMs?: number): GSDToolsError {
|
||||||
return GSDToolsError.timeout(message, command, args, stderr, timeoutMs);
|
return GSDToolsError.timeout(message, command, args, stderr, timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function failureToolsError(
|
function failureToolsError(
|
||||||
message: string,
|
message: string,
|
||||||
command: string,
|
command: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
|
|||||||
Reference in New Issue
Block a user