refactor: share cli runtime error handling

This commit is contained in:
Peter Steinberger committed 2026-01-19 00:52:31 +00:00
1 parent c532d161c4
commit 1fec41b3df
16 files changed
+288 -452

No files matched your search

+17
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);
}
}