Skip to content

Commit 53d187a

Browse files
committed
Clean up job error stacks like we do for logging
1 parent 329262b commit 53d187a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/core/queue/queue.patch.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BullModule } from '@nestjs/bullmq';
22
import type { Type } from '@nestjs/common';
3-
import { cleanJoin, setInspectOnClass } from '@seedcompany/common';
3+
import { cleanJoin, patchMethod, setInspectOnClass } from '@seedcompany/common';
44
import { Case } from '@seedcompany/common/case';
55
import {
66
type FlowJob,
@@ -10,6 +10,7 @@ import {
1010
RedisConnection,
1111
Worker,
1212
} from 'bullmq';
13+
import { prettyStack } from '../exception';
1314

1415
type QueueCls = Type<Queue<any>> & { NAME?: string };
1516

@@ -48,6 +49,14 @@ export class Queue<TJob extends Job> extends QueueBase<TJob> {
4849
}
4950
BullModule.queueClass = Queue;
5051

52+
// Patch error handling to strip off non-src frames (etc) like we do for logging.
53+
patchMethod(Job.prototype, 'moveToFailed', (base) => (...args) => {
54+
const error = args[0];
55+
error.stack = prettyStack(error);
56+
57+
return base(...args);
58+
});
59+
5160
setInspectOnClass(Job, (job) => ({
5261
collapsedId: cleanJoin(' - ', [job.queueName, job.id, job.name]),
5362
exclude: ['toKey', 'scripts', 'queueQualifiedName'],

0 commit comments

Comments
 (0)