refactor: centralize gsd-tools error wrapping path

This commit is contained in:
Tom Boucher
2026-05-04 20:20:39 -04:00
parent 6059a574f2
commit 0fffc7c055

View File

@@ -118,17 +118,22 @@ export class GSDTools {
registryArgs: string[], registryArgs: string[],
mode: 'json' | 'raw', mode: 'json' | 'raw',
): Promise<unknown> { ): Promise<unknown> {
try { return this.executeWithToolsError(legacyCommand, legacyArgs, () =>
return await this.nativeHotpathAdapter.dispatch( this.nativeHotpathAdapter.dispatch(
legacyCommand, legacyCommand,
legacyArgs, legacyArgs,
registryCommand, registryCommand,
registryArgs, registryArgs,
mode, mode,
); ));
}
private async executeWithToolsError<T>(command: string, args: string[], work: () => Promise<T>): Promise<T> {
try {
return await work();
} catch (err) { } catch (err) {
if (err instanceof GSDToolsError) throw err; if (err instanceof GSDToolsError) throw err;
throw this.toToolsError(legacyCommand, legacyArgs, err); throw this.toToolsError(command, args, err);
} }
} }
@@ -139,12 +144,7 @@ export class GSDTools {
* Handles the `@file:` prefix pattern for large results. * Handles the `@file:` prefix pattern for large results.
*/ */
async exec(command: string, args: string[] = []): Promise<unknown> { async exec(command: string, args: string[] = []): Promise<unknown> {
try { return this.executeWithToolsError(command, args, () => this.commandExecutor.exec(command, args, 'json'));
return await this.commandExecutor.exec(command, args, 'json');
} catch (err) {
if (err instanceof GSDToolsError) throw err;
throw this.toToolsError(command, args, err);
}
} }
// ─── Raw exec (no JSON parsing) ─────────────────────────────────────── // ─── Raw exec (no JSON parsing) ───────────────────────────────────────
@@ -154,12 +154,7 @@ export class GSDTools {
* Use for commands like `config-set` that return plain text, not JSON. * Use for commands like `config-set` that return plain text, not JSON.
*/ */
async execRaw(command: string, args: string[] = []): Promise<string> { async execRaw(command: string, args: string[] = []): Promise<string> {
try { return this.executeWithToolsError(command, args, async () => this.commandExecutor.exec(command, args, 'raw') as string);
return await this.commandExecutor.exec(command, args, 'raw') as string;
} catch (err) {
if (err instanceof GSDToolsError) throw err;
throw this.toToolsError(command, args, err);
}
} }