refactor: add typed query failure signals
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
import { GSDToolsError } from './gsd-tools-error.js';
|
||||
|
||||
export interface QueryFailureSignal {
|
||||
kind: 'timeout' | 'failure';
|
||||
message: string;
|
||||
timeoutMs?: number;
|
||||
}
|
||||
|
||||
export function errorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
@@ -22,3 +30,19 @@ export function isTimeoutLikeError(error: unknown): boolean {
|
||||
export function timeoutMessage(command: string, args: string[], timeoutMs: number): string {
|
||||
return `gsd-tools timed out after ${timeoutMs}ms: ${command} ${args.join(' ')}`;
|
||||
}
|
||||
|
||||
export function toFailureSignal(error: unknown): QueryFailureSignal {
|
||||
if (error instanceof GSDToolsError && error.classification) {
|
||||
return {
|
||||
kind: error.classification.kind,
|
||||
message: error.message,
|
||||
timeoutMs: error.classification.timeoutMs,
|
||||
};
|
||||
}
|
||||
|
||||
const message = errorMessage(error);
|
||||
if (isTimeoutMessage(message)) {
|
||||
return { kind: 'timeout', message, timeoutMs: parseTimeoutMs(message) };
|
||||
}
|
||||
return { kind: 'failure', message };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user