Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sandboxed): fix detecting special errors by sending default messages #2967

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this still work if the user passes a different message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it will

}
});
};
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
Loading