MCPcopy
hub / github.com/triggerdotdev/trigger.dev / wrapCommandAction

Function wrapCommandAction

packages/cli-v3/src/cli/common.ts:50–98  ·  view source on GitHub ↗
(
  name: string,
  schema: T,
  options: unknown,
  action: (opts: z.output<T>) => Promise<TResult>
)

Source from the content-addressed store, hash-verified

48export const tracer = getTracer();
49
50export async function wrapCommandAction<T extends z.AnyZodObject, TResult>(
51 name: string,
52 schema: T,
53 options: unknown,
54 action: (opts: z.output<T>) => Promise<TResult>
55): Promise<TResult> {
56 return await tracer.startActiveSpan(name, async (span) => {
57 try {
58 const parsedOptions = schema.safeParse(options);
59
60 if (!parsedOptions.success) {
61 throw new Error(fromZodError(parsedOptions.error).toString());
62 }
63
64 span.setAttributes({
65 ...flattenAttributes(parsedOptions.data, "cli.options"),
66 });
67
68 logger.loggerLevel = parsedOptions.data.logLevel;
69
70 logger.debug(`Running "${name}" with the following options`, {
71 options: options,
72 spanContext: span?.spanContext(),
73 });
74
75 const result = await action(parsedOptions.data);
76
77 span.end();
78
79 return result;
80 } catch (e) {
81 if (e instanceof SkipLoggingError) {
82 recordSpanException(span, e);
83 } else if (e instanceof OutroCommandError) {
84 outro("Operation cancelled");
85 } else if (e instanceof SkipCommandError) {
86 // do nothing
87 } else {
88 recordSpanException(span, e);
89
90 logger.log(`${chalkError("X Error:")} ${e instanceof Error ? e.message : String(e)}`);
91 }
92
93 span.end();
94
95 throw e;
96 }
97 });
98}

Callers 8

configureDevCommandFunction · 0.85
deployCommandFunction · 0.85
whoAmICommandFunction · 0.85
configureUpdateCommandFunction · 0.85
loginCommandFunction · 0.85
initCommandFunction · 0.85
logoutCommandFunction · 0.85
listProfilesCommandFunction · 0.85

Calls 8

flattenAttributesFunction · 0.90
chalkErrorFunction · 0.90
recordSpanExceptionFunction · 0.85
startActiveSpanMethod · 0.80
toStringMethod · 0.80
debugMethod · 0.65
logMethod · 0.65
actionFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…