Skip to content

Commit

Permalink
fix(sandboxed): fix detecting special errors by sending default messa…
Browse files Browse the repository at this point in the history
…ges (#2967) fixes #2962
  • Loading branch information
roggervalf authored Dec 18, 2024
1 parent e758d23 commit 52b0e34
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/classes/errors/delayed-error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const DELAYED_ERROR = 'bullmq:movedToDelayed';

/**
* DelayedError
*
Expand All @@ -6,7 +8,7 @@
*
*/
export class DelayedError extends Error {
constructor(message?: string) {
constructor(message: string = DELAYED_ERROR) {
super(message);
this.name = this.constructor.name;
Object.setPrototypeOf(this, new.target.prototype);
Expand Down
4 changes: 3 additions & 1 deletion src/classes/errors/unrecoverable-error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const UNRECOVERABLE_ERROR = 'bullmq:unrecoverable';

/**
* UnrecoverableError
*
Expand All @@ -6,7 +8,7 @@
*
*/
export class UnrecoverableError extends Error {
constructor(message?: string) {
constructor(message: string = UNRECOVERABLE_ERROR) {
super(message);
this.name = this.constructor.name;
Object.setPrototypeOf(this, new.target.prototype);
Expand Down
4 changes: 3 additions & 1 deletion src/classes/errors/waiting-children-error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const WAITING_CHILDREN_ERROR = 'bullmq:movedToWaitingChildren';

/**
* WaitingChildrenError
*
Expand All @@ -6,7 +8,7 @@
*
*/
export class WaitingChildrenError extends Error {
constructor(message?: string) {
constructor(message: string = WAITING_CHILDREN_ERROR) {
super(message);
this.name = this.constructor.name;
Object.setPrototypeOf(this, new.target.prototype);
Expand Down
2 changes: 1 addition & 1 deletion src/classes/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
invertObject,
} from '../utils';
import { Backoffs } from './backoffs';
import { Scripts, raw2NextJobData } from './scripts';
import { Scripts } from './scripts';
import { UnrecoverableError } from './errors/unrecoverable-error';
import type { QueueEvents } from './queue-events';
import { SpanKind } from '../enums';
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/fixture_processor_unrecoverable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function (job) {
throw new Error('Not yet!');
}
if (job.attemptsMade < 2) {
throw new UnrecoverableError('Unrecoverable');
throw new UnrecoverableError();
}
});
};
13 changes: 10 additions & 3 deletions tests/test_sandboxed_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { expect } from 'chai';
import { pathToFileURL } from 'url';
import { default as IORedis } from 'ioredis';
import { after } from 'lodash';
import { FlowProducer, Job, Queue, QueueEvents, Worker } from '../src/classes';
import {
FlowProducer,
Job,
Queue,
QueueEvents,
UNRECOVERABLE_ERROR,
Worker,
} from '../src/classes';
import { beforeEach, before, after as afterAll, it } from 'mocha';
import { v4 } from 'uuid';
import { delay, removeAllQueueData } from '../src/utils';
Expand Down Expand Up @@ -501,7 +508,7 @@ function sandboxProcessTests(
'test',
{ foo: 'bar' },
{
attempts: 3,
attempts: 5,
backoff: 1000,
},
);
Expand All @@ -512,7 +519,7 @@ function sandboxProcessTests(
after(2, (job: Job, error) => {
const elapse = Date.now() - start;
expect(error.name).to.be.eql('UnrecoverableError');
expect(error.message).to.be.eql('Unrecoverable');
expect(error.message).to.be.eql(UNRECOVERABLE_ERROR);
expect(elapse).to.be.greaterThan(1000);
expect(job.attemptsMade).to.be.eql(2);
resolve();
Expand Down

0 comments on commit 52b0e34

Please sign in to comment.