diff --git a/src/classes/errors/delayed-error.ts b/src/classes/errors/delayed-error.ts index 7e04fad7c2..309805c894 100644 --- a/src/classes/errors/delayed-error.ts +++ b/src/classes/errors/delayed-error.ts @@ -1,3 +1,5 @@ +export const DELAYED_ERROR = 'bullmq:movedToDelayed'; + /** * DelayedError * @@ -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); diff --git a/src/classes/errors/unrecoverable-error.ts b/src/classes/errors/unrecoverable-error.ts index 6a48e04902..e46db6fb68 100644 --- a/src/classes/errors/unrecoverable-error.ts +++ b/src/classes/errors/unrecoverable-error.ts @@ -1,3 +1,5 @@ +export const UNRECOVERABLE_ERROR = 'bullmq:unrecoverable'; + /** * UnrecoverableError * @@ -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); diff --git a/src/classes/errors/waiting-children-error.ts b/src/classes/errors/waiting-children-error.ts index a9859fbd59..45877af553 100644 --- a/src/classes/errors/waiting-children-error.ts +++ b/src/classes/errors/waiting-children-error.ts @@ -1,3 +1,5 @@ +export const WAITING_CHILDREN_ERROR = 'bullmq:movedToWaitingChildren'; + /** * WaitingChildrenError * @@ -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); diff --git a/src/classes/job.ts b/src/classes/job.ts index 531839e62c..ec63e0027b 100644 --- a/src/classes/job.ts +++ b/src/classes/job.ts @@ -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'; diff --git a/tests/fixtures/fixture_processor_unrecoverable.js b/tests/fixtures/fixture_processor_unrecoverable.js index 57b39f9233..0fdde7c58b 100644 --- a/tests/fixtures/fixture_processor_unrecoverable.js +++ b/tests/fixtures/fixture_processor_unrecoverable.js @@ -13,7 +13,7 @@ module.exports = function (job) { throw new Error('Not yet!'); } if (job.attemptsMade < 2) { - throw new UnrecoverableError('Unrecoverable'); + throw new UnrecoverableError(); } }); }; diff --git a/tests/test_sandboxed_process.ts b/tests/test_sandboxed_process.ts index c246a06458..0635200ff2 100644 --- a/tests/test_sandboxed_process.ts +++ b/tests/test_sandboxed_process.ts @@ -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'; @@ -501,7 +508,7 @@ function sandboxProcessTests( 'test', { foo: 'bar' }, { - attempts: 3, + attempts: 5, backoff: 1000, }, ); @@ -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();