MCPcopy Create free account
hub / github.com/Snapchat/Valdi / makeCommandHandler

Function makeCommandHandler

npm_modules/cli/src/utils/errorUtils.ts:37–63  ·  view source on GitHub ↗
(cb: (argv: ArgumentsResolver<T>) => Promise<void>)

Source from the content-addressed store, hash-verified

35}
36
37export function makeCommandHandler<T>(cb: (argv: ArgumentsResolver<T>) => Promise<void>): (argv: T) => void {
38 const command = async (argv: T) => {
39 const argumentsResolver = new ArgumentsResolver(argv);
40 try {
41 await cb(argumentsResolver);
42 process.exitCode = 0;
43 } catch (error) {
44 process.exitCode = 1;
45
46 if (error instanceof CliError) {
47 // Managed Error
48 console.log(wrapInColor(error.message, error.textColor));
49 } else if (error instanceof Error) {
50 // Unmanaged Error
51 console.log(error.stack);
52 console.log(wrapInColor(error.message, ANSI_COLORS.RED_COLOR));
53 } else {
54 // Something went really wrong
55 throw error;
56 }
57 }
58 };
59
60 return (argv: T) => {
61 void command(argv);
62 };
63}

Callers 15

doctor.tsFile · 0.90
test.tsFile · 0.90
projectsync.tsFile · 0.90
devSetup.tsFile · 0.90
newModule.tsFile · 0.90
install.tsFile · 0.90
hotreload.tsFile · 0.90
export.tsFile · 0.90
bootstrap.tsFile · 0.90
agentCheck.tsFile · 0.90
preview.tsFile · 0.90
log.tsFile · 0.90

Calls 1

commandFunction · 0.85

Tested by

no test coverage detected