Skip to content

Commit e6ea68e

Browse files
authored
fix: ensure job errors are saved in payload (#9644)
Previously, job errors were not saved in payload
1 parent 1e8c9d3 commit e6ea68e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/payload/src/queues/operations/runJobs/runJob/getRunTaskFunction.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ export async function handleTaskFailed({
7979
if (!job.log) {
8080
job.log = []
8181
}
82+
const errorJSON = error
83+
? {
84+
name: error.name,
85+
message: error.message,
86+
stack: error.stack,
87+
}
88+
: runnerOutput.state
89+
8290
job.log.push({
8391
completedAt: new Date().toISOString(),
84-
error: error ?? runnerOutput.state,
92+
error: errorJSON,
8593
executedAt: executedAt.toISOString(),
8694
input,
8795
output,

packages/payload/src/queues/operations/runJobs/runJob/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,17 @@ export const runJob = async ({
5656
workflowConfig,
5757
})
5858

59+
const errorJSON = hasFinalError
60+
? {
61+
name: err.name,
62+
message: err.message,
63+
stack: err.stack,
64+
}
65+
: undefined
5966
// Tasks update the job if they error - but in case there is an unhandled error (e.g. in the workflow itself, not in a task)
6067
// we need to ensure the job is updated to reflect the error
6168
await updateJob({
62-
error: hasFinalError ? err : undefined,
69+
error: errorJSON,
6370
hasError: hasFinalError, // If reached max retries => final error. If hasError is true this job will not be retried
6471
processing: false,
6572
totalTried: (job.totalTried ?? 0) + 1,

0 commit comments

Comments
 (0)