refactor: isolate native dispatch error projection
This commit is contained in:
@@ -19,8 +19,7 @@ export class QueryNativeDirectAdapter {
|
|||||||
try {
|
try {
|
||||||
return await this.withTimeout(legacyCommand, legacyArgs, this.deps.dispatch(registryCommand, registryArgs));
|
return await this.withTimeout(legacyCommand, legacyArgs, this.deps.dispatch(registryCommand, registryArgs));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof GSDToolsError) throw error;
|
throw this.toNativeDispatchError(legacyCommand, legacyArgs, error);
|
||||||
throw this.deps.createNativeFailureError(errorMessage(error), legacyCommand, legacyArgs, error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +33,11 @@ export class QueryNativeDirectAdapter {
|
|||||||
return formatQueryRawOutput(registryCommand, result.data).trim();
|
return formatQueryRawOutput(registryCommand, result.data).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private toNativeDispatchError(legacyCommand: string, legacyArgs: string[], error: unknown): GSDToolsError {
|
||||||
|
if (error instanceof GSDToolsError) return error;
|
||||||
|
return this.deps.createNativeFailureError(errorMessage(error), legacyCommand, legacyArgs, error);
|
||||||
|
}
|
||||||
|
|
||||||
private async withTimeout<T>(legacyCommand: string, legacyArgs: string[], work: Promise<T>): Promise<T> {
|
private async withTimeout<T>(legacyCommand: string, legacyArgs: string[], work: Promise<T>): Promise<T> {
|
||||||
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
||||||
const timeoutPromise = new Promise<never>((_, reject) => {
|
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user