refactor(query): deepen command/dispatch seams and resolve coderabbit findings
* refactor(query): deepen command definition seam and fold fallback mapping cleanup * refactor(query): add shared dispatch formatting module seam * fix(query): restore QueryResult type import in dispatch deps * test/query: align raw-output policy and definition normalization contracts * refactor(query): deepen diagnosis, invariant report, and error taxonomy seams * refactor(query): deepen dispatch plan, fallback bridge, policy snapshot, and hints seams * refactor(query): deepen validation, fallback policy, capability, and result builder seams * refactor(query): deepen resolution strategy, output classifier, observability, and policy-capability seams * refactor(query): finalize deep strategy/classifier/observability/capability seams * test/query: address coderabbit inline and out-of-diff dispatch nits * fix(query): address remaining coderabbit input-validation and bridge stderr threads * fix(query): address remaining coderabbit dispatch and strategy/output nits
This commit is contained in:
@@ -1,46 +1,25 @@
|
||||
import type { QueryDispatchError, QueryDispatchErrorKind, QueryDispatchResult } from './query-dispatch-contract.js';
|
||||
import type { QueryDispatchError, QueryDispatchResult } from './query-dispatch-contract.js';
|
||||
import { fallbackFailureError, nativeFailureError, nativeTimeoutError } from './query-error-taxonomy.js';
|
||||
import { dispatchFailure } from './query-dispatch-result-builder.js';
|
||||
|
||||
export function toDispatchFailure(
|
||||
error: QueryDispatchError,
|
||||
stderr: string[] = [],
|
||||
): QueryDispatchResult {
|
||||
return {
|
||||
ok: false,
|
||||
stderr,
|
||||
exit_code: error.code,
|
||||
error,
|
||||
};
|
||||
return dispatchFailure(error, stderr);
|
||||
}
|
||||
|
||||
export function mapNativeDispatchError(error: unknown, command: string, args: string[]): QueryDispatchError {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const kind: QueryDispatchErrorKind = message.includes('timed out after')
|
||||
? 'native_timeout'
|
||||
: 'native_failure';
|
||||
return {
|
||||
kind,
|
||||
code: 1,
|
||||
message: `Error: ${message}`,
|
||||
details: {
|
||||
command,
|
||||
args,
|
||||
...(kind === 'native_timeout' ? { timeout_ms: parseTimeoutMs(message) } : {}),
|
||||
},
|
||||
};
|
||||
if (/timed out after/i.test(message)) {
|
||||
return nativeTimeoutError({ message, command, args, timeoutMs: parseTimeoutMs(message) });
|
||||
}
|
||||
return nativeFailureError({ message, command, args });
|
||||
}
|
||||
|
||||
export function mapFallbackDispatchError(error: unknown, command: string, args: string[]): QueryDispatchError {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
kind: 'fallback_failure',
|
||||
code: 1,
|
||||
message: `Error: gsd-tools.cjs fallback failed: ${message}`,
|
||||
details: {
|
||||
command,
|
||||
args,
|
||||
backend: 'cjs',
|
||||
},
|
||||
};
|
||||
return fallbackFailureError({ message, command, args, backend: 'cjs' });
|
||||
}
|
||||
|
||||
function parseTimeoutMs(message: string): number | undefined {
|
||||
|
||||
Reference in New Issue
Block a user