Skip to content

Commit fc2aa37

Browse files
NicolappsConvex, Inc.
authored andcommitted
node-executor: include err message in stack trace (#40606)
This fixes our implementation of `Error.prepareStackTrace` to include the error message when available. This matches the default behavior in v8/Node.js (https://v8.dev/docs/stack-trace-api) and can make it easier for Convex users to debug their apps. This also helps us internally understand errors in node-executor integration tests. GitOrigin-RevId: 2f4f579379c5eab68c53de9e7e3e77c89b7b0710
1 parent 4624d96 commit fc2aa37

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

npm-packages/js-integration-tests/convex/stacktraceNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ async function wontBeInTheStackTrace(): Promise<string> {
5050
});
5151
});
5252
}
53+
54+
export const errorWithMessage = action(() => {
55+
return new Error("custom error message").stack;
56+
});

npm-packages/js-integration-tests/stacktrace_node.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,12 @@ describe("Node.js user space stack traces", () => {
8282
expect(canonicalResult).toEqual(canonicalExpected);
8383
// sometimes flakes at 20000ms
8484
}, 30000);
85+
86+
test("stack trace with an error message", async () => {
87+
const result = await client.action(api.stacktraceNode.errorWithMessage);
88+
const canonicalResult = canonicalize(result);
89+
expect(
90+
canonicalResult?.startsWith(`Error: custom error message\n at `),
91+
).toBe(true);
92+
}, 30000);
8593
});

npm-packages/node-executor/src/errors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ export function registerPrepareStackTrace(modulesDir: string) {
100100
//
101101
// TODO find a library to do this properly: once we provide it libraries will depend on it matching Node.js stack traces.
102102

103-
return `Error\n${frameData
103+
const errorMessage = extractErrorMessage(error);
104+
105+
return `Error${errorMessage !== "" ? `: ${errorMessage}` : ""}\n${frameData
104106
.map((frame) => formatTraceLine(frame))
105107
.join("\n")}`;
106108
};

0 commit comments

Comments
 (0)