refactor: centralize typed GSDToolsError construction

This commit is contained in:
Tom Boucher
2026-05-04 20:03:56 -04:00
parent 7dcafbc211
commit 41683b2f53
4 changed files with 63 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ import { QuerySubprocessAdapter } from './query-subprocess-adapter.js';
import { QueryNativeDirectAdapter } from './query-native-direct-adapter.js';
import { QueryNativeHotpathAdapter } from './query-native-hotpath-adapter.js';
import { formatQueryRawOutput } from './query-raw-output-projection.js';
import { failureClassification, GSDToolsError, timeoutClassification } from './gsd-tools-error.js';
import { GSDToolsError } from './gsd-tools-error.js';
export interface GSDToolsRuntime {
registry: ReturnType<typeof createRegistry>;
@@ -34,16 +34,16 @@ export function createGSDToolsRuntime(opts: {
timeoutMs: opts.timeoutMs,
workstream: opts.workstream,
createToolsError: (message, command, args, exitCode, stderr, classification) =>
new GSDToolsError(message, command, args, exitCode, stderr, {
classification: classification ?? failureClassification(),
}),
classification?.kind === 'timeout'
? GSDToolsError.timeout(message, command, args, stderr, classification.timeoutMs, { exitCode })
: GSDToolsError.failure(message, command, args, exitCode, stderr),
});
const nativeDirectAdapter = new QueryNativeDirectAdapter({
timeoutMs: opts.timeoutMs,
dispatch: (registryCommand, registryArgs) => registry.dispatch(registryCommand, registryArgs, opts.projectDir),
createTimeoutError: (message, command, args) =>
new GSDToolsError(message, command, args, null, '', { classification: timeoutClassification(opts.timeoutMs) }),
GSDToolsError.timeout(message, command, args, '', opts.timeoutMs),
});
const transport = new GSDTransport(registry, {