Skip to content

Commit 4e3effe

Browse files
devin-ai-integration[bot]Convex, Inc.
authored andcommitted
Improve run command error handling to show available functions (#37904)
GitOrigin-RevId: be73f6374ec11646cd5646976798767e8fafaca8
1 parent dcecd1a commit 4e3effe

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/cli/lib/run.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,65 @@ export async function runFunctionAndLog(
5757
functionArgs,
5858
);
5959
} catch (err) {
60+
const errorMessage = (err as Error).toString().trim();
61+
62+
if (errorMessage.includes("Could not find function")) {
63+
const functions = (await runSystemQuery(ctx, {
64+
deploymentUrl: args.deploymentUrl,
65+
adminKey: args.adminKey,
66+
functionName: "_system/cli/modules:apiSpec",
67+
componentPath: args.componentPath,
68+
args: {},
69+
})) as (
70+
| {
71+
functionType: "Query" | "Mutation" | "Action";
72+
identifier: string;
73+
}
74+
| {
75+
functionType: "HttpAction";
76+
}
77+
)[];
78+
79+
const functionNames = functions
80+
.filter(
81+
(
82+
fn,
83+
): fn is {
84+
functionType: "Query" | "Mutation" | "Action";
85+
identifier: string;
86+
} => fn.functionType !== "HttpAction",
87+
)
88+
.map(({ identifier }) => {
89+
const separatorPos = identifier.indexOf(":");
90+
91+
const path =
92+
separatorPos === -1
93+
? ""
94+
: identifier.substring(0, separatorPos + 1);
95+
const name =
96+
separatorPos === -1
97+
? identifier
98+
: identifier.substring(separatorPos + 1);
99+
100+
return `• ${chalk.gray(path)}${name}`;
101+
});
102+
103+
const availableFunctionsMessage =
104+
functionNames.length > 0
105+
? `Available functions:\n${functionNames.join("\n")}`
106+
: "No functions found.";
107+
108+
return await ctx.crash({
109+
exitCode: 1,
110+
errorType: "invalid filesystem data",
111+
printedMessage: `Failed to run function "${args.functionName}":\n${chalk.red(errorMessage)}\n\n${availableFunctionsMessage}`,
112+
});
113+
}
114+
60115
return await ctx.crash({
61116
exitCode: 1,
62117
errorType: "invalid filesystem or env vars",
63-
printedMessage: `Failed to run function "${args.functionName}":\n${chalk.red((err as Error).toString().trim())}`,
118+
printedMessage: `Failed to run function "${args.functionName}":\n${chalk.red(errorMessage)}`,
64119
});
65120
}
66121

0 commit comments

Comments
 (0)