refactor: share cli runtime error handling

This commit is contained in:
Peter Steinberger
2026-01-19 00:52:17 +00:00
parent c532d161c4
commit 1fec41b3df
16 changed files with 288 additions and 452 deletions

View File

@@ -29,3 +29,20 @@ export async function withManager<T>(params: {
}
}
}
export async function runCommandWithRuntime(
runtime: { error: (message: string) => void; exit: (code: number) => void },
action: () => Promise<void>,
onError?: (error: unknown) => void,
): Promise<void> {
try {
await action();
} catch (err) {
if (onError) {
onError(err);
return;
}
runtime.error(String(err));
runtime.exit(1);
}
}