Skip to content

Commit 92efb18

Browse files
authored
DX-2134: export error stack trace in error response (#132)
* feat: export error stack trace in error response * fix: add failStack to failure function
1 parent 54e3623 commit 92efb18

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const formatWorkflowError = (error: unknown): FailureFunctionPayload => {
6767
? {
6868
error: error.name,
6969
message: error.message,
70+
stack: error.stack,
7071
}
7172
: {
7273
error: "Error",

src/serve/serve.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ describe("serve", () => {
322322
expect(result).toEqual({
323323
error: "Error",
324324
message: "some-error",
325+
stack: expect.any(String),
325326
});
326327
called = true;
327328
},
@@ -903,6 +904,7 @@ describe("serve", () => {
903904
expect(body).toEqual({
904905
error: "WorkflowNonRetryableError",
905906
message: "This is a non-retryable error",
907+
stack: expect.any(String),
906908
});
907909
},
908910
responseFields: { body: undefined, status: 489 },
@@ -1227,6 +1229,7 @@ describe("serve", () => {
12271229
expect(content).toEqual({
12281230
error: "WorkflowError",
12291231
message: `Workflow URL should start with 'http://' or 'https://'. Recevied is '${url}'`,
1232+
stack: expect.any(String),
12301233
});
12311234

12321235
expect(logSpy).toBeCalledWith("WARN", "ENDPOINT_START", {

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export type WorkflowServeOptions<
230230
failStatus: number;
231231
failResponse: string;
232232
failHeaders: Record<string, string[]>;
233+
failStack: string;
233234
}) => Promise<void | string> | void | string;
234235
/**
235236
* Base Url of the workflow endpoint
@@ -360,6 +361,10 @@ export type FailureFunctionPayload = {
360361
* error message
361362
*/
362363
message: string;
364+
/**
365+
* error stack trace if available
366+
*/
367+
stack?: string;
363368
};
364369

365370
/**

src/workflow-parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,15 @@ export const handleFailure = async <TInitialPayload>(
343343

344344
const decodedBody = body ? decodeBase64(body) : "{}";
345345
let errorMessage: string = "";
346+
let failStack: string = "";
346347
try {
347348
const errorPayload = JSON.parse(decodedBody) as FailureFunctionPayload;
348349
if (errorPayload.message) {
349350
errorMessage = errorPayload.message;
350351
}
352+
if (errorPayload.stack) {
353+
failStack = errorPayload.stack;
354+
}
351355
} catch {
352356
// skip
353357
}
@@ -398,6 +402,7 @@ export const handleFailure = async <TInitialPayload>(
398402
failStatus: status,
399403
failResponse: errorMessage,
400404
failHeaders: header,
405+
failStack,
401406
});
402407
return ok({ result: "is-failure-callback", response: failureResponse });
403408
} catch (error) {

0 commit comments

Comments
 (0)