refactor: consolidate nodes cli error handling
This commit is contained in:
13
src/cli/nodes-cli/cli-utils.ts
Normal file
13
src/cli/nodes-cli/cli-utils.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { runCommandWithRuntime } from "../cli-utils.js";
|
||||
import { unauthorizedHintForMessage } from "./rpc.js";
|
||||
|
||||
export function runNodesCommand(label: string, action: () => Promise<void>) {
|
||||
return runCommandWithRuntime(defaultRuntime, action, (err) => {
|
||||
const message = String(err);
|
||||
defaultRuntime.error(`nodes ${label} failed: ${message}`);
|
||||
const hint = unauthorizedHintForMessage(message);
|
||||
if (hint) defaultRuntime.error(hint);
|
||||
defaultRuntime.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user