refactor: share cli runtime error handling
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user