|  | 
|  | 1 | +import { createJsonErrorObject } from "../src/v3/errors.js"; | 
|  | 2 | +import type { TaskRunError } from "../src/v3/schemas/common.js"; | 
|  | 3 | + | 
|  | 4 | +describe("createJsonErrorObject", () => { | 
|  | 5 | +  it("should filter internal framework noise from error stack traces", () => { | 
|  | 6 | +    const taskRunError: TaskRunError = { | 
|  | 7 | +      type: "BUILT_IN_ERROR", | 
|  | 8 | +      name: "Error", | 
|  | 9 | +      message: "Network error occurred", | 
|  | 10 | +      stackTrace: `Error: Network error occurred | 
|  | 11 | +    at fetchData (file:///src/trigger/utils/helper.ts:4:9) | 
|  | 12 | +    at processResponse (file:///src/trigger/utils/helper.ts:9:10) | 
|  | 13 | +    at parseResult (file:///src/trigger/utils/helper.ts:14:10) | 
|  | 14 | +    at callAPI (file:///src/trigger/services/api.ts:6:10) | 
|  | 15 | +    at localHelper (file:///src/trigger/example.ts:7:10) | 
|  | 16 | +    at run (file:///src/trigger/example.ts:17:12) | 
|  | 17 | +    at _tracer.startActiveSpan.attributes (file:///.npm/_npx/f51a09bd0abf5f10/node_modules/@trigger.dev/core/src/v3/workers/taskExecutor.ts:445:38) | 
|  | 18 | +    at file:///.npm/_npx/f51a09bd0abf5f10/node_modules/@trigger.dev/core/src/v3/tracer.ts:137:24 | 
|  | 19 | +    at AsyncLocalStorage.run (node:async_hooks:346:14) | 
|  | 20 | +    at AsyncLocalStorageContextManager.with (file:///.npm/_npx/f51a09bd0abf5f10/node_modules/@opentelemetry/context-async-hooks/src/AsyncLocalStorageContextManager.ts:40:36)`, | 
|  | 21 | +    }; | 
|  | 22 | + | 
|  | 23 | +    const jsonError = createJsonErrorObject(taskRunError); | 
|  | 24 | + | 
|  | 25 | +    // Should preserve user stack traces | 
|  | 26 | +    expect(jsonError.stackTrace).toContain( | 
|  | 27 | +      "at fetchData (file:///src/trigger/utils/helper.ts:4:9)" | 
|  | 28 | +    ); | 
|  | 29 | +    expect(jsonError.stackTrace).toContain( | 
|  | 30 | +      "at processResponse (file:///src/trigger/utils/helper.ts:9:10)" | 
|  | 31 | +    ); | 
|  | 32 | +    expect(jsonError.stackTrace).toContain( | 
|  | 33 | +      "at parseResult (file:///src/trigger/utils/helper.ts:14:10)" | 
|  | 34 | +    ); | 
|  | 35 | +    expect(jsonError.stackTrace).toContain("at callAPI (file:///src/trigger/services/api.ts:6:10)"); | 
|  | 36 | +    expect(jsonError.stackTrace).toContain("at localHelper (file:///src/trigger/example.ts:7:10)"); | 
|  | 37 | +    expect(jsonError.stackTrace).toContain("at run (file:///src/trigger/example.ts:17:12)"); | 
|  | 38 | + | 
|  | 39 | +    // Should filter framework noise | 
|  | 40 | +    expect(jsonError.stackTrace).not.toContain("_tracer.startActiveSpan.attributes"); | 
|  | 41 | +    expect(jsonError.stackTrace).not.toContain("taskExecutor.ts"); | 
|  | 42 | +    expect(jsonError.stackTrace).not.toContain("tracer.ts"); | 
|  | 43 | +    expect(jsonError.stackTrace).not.toContain("AsyncLocalStorage.run"); | 
|  | 44 | +    expect(jsonError.stackTrace).not.toContain("AsyncLocalStorageContextManager"); | 
|  | 45 | +    expect(jsonError.stackTrace).not.toContain("node_modules/@trigger.dev/core"); | 
|  | 46 | +    expect(jsonError.stackTrace).not.toContain(".npm/_npx"); | 
|  | 47 | +  }); | 
|  | 48 | +}); | 
0 commit comments