Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 .changeset/dry-taxis-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

Improve user-facing error readability by filtering framework noise from stack traces
5 changes: 4 additions & 1 deletion 5 packages/core/src/v3/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export function createJsonErrorObject(error: TaskRunError): SerializedError {
return {
name: enhancedError.name,
message: enhancedError.message,
stackTrace: enhancedError.stackTrace,
stackTrace: correctErrorStackTrace(enhancedError.stackTrace, undefined, {
removeFirstLine: false,
}),
};
}
case "STRING_ERROR": {
Expand Down Expand Up @@ -400,6 +402,7 @@ const LINES_TO_IGNORE = [
/ZodIpc/,
/startActiveSpan/,
/processTicksAndRejections/,
/AsyncLocalStorage/,
];

function correctStackTraceLine(line: string, projectDir?: string, isDev?: boolean) {
Expand Down
48 changes: 48 additions & 0 deletions 48 packages/core/test/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { createJsonErrorObject } from "../src/v3/errors.js";
import type { TaskRunError } from "../src/v3/schemas/common.js";

describe("createJsonErrorObject", () => {
it("should filter internal framework noise from error stack traces", () => {
const taskRunError: TaskRunError = {
type: "BUILT_IN_ERROR",
name: "Error",
message: "Network error occurred",
stackTrace: `Error: Network error occurred
at fetchData (file:///src/trigger/utils/helper.ts:4:9)
at processResponse (file:///src/trigger/utils/helper.ts:9:10)
at parseResult (file:///src/trigger/utils/helper.ts:14:10)
at callAPI (file:///src/trigger/services/api.ts:6:10)
at localHelper (file:///src/trigger/example.ts:7:10)
at run (file:///src/trigger/example.ts:17:12)
at _tracer.startActiveSpan.attributes (file:///.npm/_npx/f51a09bd0abf5f10/node_modules/@trigger.dev/core/src/v3/workers/taskExecutor.ts:445:38)
at file:///.npm/_npx/f51a09bd0abf5f10/node_modules/@trigger.dev/core/src/v3/tracer.ts:137:24
at AsyncLocalStorage.run (node:async_hooks:346:14)
at AsyncLocalStorageContextManager.with (file:///.npm/_npx/f51a09bd0abf5f10/node_modules/@opentelemetry/context-async-hooks/src/AsyncLocalStorageContextManager.ts:40:36)`,
};

const jsonError = createJsonErrorObject(taskRunError);

// Should preserve user stack traces
expect(jsonError.stackTrace).toContain(
"at fetchData (file:///src/trigger/utils/helper.ts:4:9)"
);
expect(jsonError.stackTrace).toContain(
"at processResponse (file:///src/trigger/utils/helper.ts:9:10)"
);
expect(jsonError.stackTrace).toContain(
"at parseResult (file:///src/trigger/utils/helper.ts:14:10)"
);
expect(jsonError.stackTrace).toContain("at callAPI (file:///src/trigger/services/api.ts:6:10)");
expect(jsonError.stackTrace).toContain("at localHelper (file:///src/trigger/example.ts:7:10)");
expect(jsonError.stackTrace).toContain("at run (file:///src/trigger/example.ts:17:12)");

// Should filter framework noise
expect(jsonError.stackTrace).not.toContain("_tracer.startActiveSpan.attributes");
expect(jsonError.stackTrace).not.toContain("taskExecutor.ts");
expect(jsonError.stackTrace).not.toContain("tracer.ts");
expect(jsonError.stackTrace).not.toContain("AsyncLocalStorage.run");
expect(jsonError.stackTrace).not.toContain("AsyncLocalStorageContextManager");
expect(jsonError.stackTrace).not.toContain("node_modules/@trigger.dev/core");
expect(jsonError.stackTrace).not.toContain(".npm/_npx");
});
Comment on lines +26 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an inline snapshot here to be able just plainly see how the cleaned up stack trace looks like

});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.