question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throw custom error class is not propagated properly to the Queue

See original GitHub issue

Hi, my worker throws a custom error class, I do see the error with the relevant class name & stack trace in the Bull-Dashboard.

But when the failed event triggered on the queue process I get only the error’s message field. https://github.com/taskforcesh/bullmq/blob/master/src/classes/job.ts#L375

class CustomError extends Error {
  public code: any;
  public details: string[];

  constructor(code, message, details) {
    super(message);

    Error.captureStackTrace(this, this.constructor);

    this.name = this.constructor.name;
    this.message = message;

    this.code = code;
    this.details = details;
  }
}

// worker - a separate process
const worker = new Worker(
  'queueName',
  async (job) => throw new CustomError(4004, 'Message not found', 'more details')
);

// queue - main process
queue = new Queue('queueName');
const job = await queue.add('test', { foo: 'bar' });
try {
  const result = await job.waitUntilFinished(queueEvents);
} catch (error) {
  // error.message will contain "Message not found"
  // here the error doesn't have any fields of the custom error event.  (such as name, code)
}

In bull-dashboard I do see the original error object, that means that the info exists in redis. image

I hope that the issue is clear, if not, I’m available for more details.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
manastcommented, Sep 20, 2020

@mattwynne I am not super positive about this idea but I may change my opinion in the future.

0reactions
mattwynnecommented, Oct 23, 2020

@drone1 I don’t understand your question, sorry.

What I’m suggesting is to remove the assumption that the error raised in the worker will neccesarily be of type Error and support a way to serialize / deserialize custom errror types.

Even if bull were opinionated about using a particular framework / library for custom errors, I think that would be fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I create a custom Error in JavaScript? - Stack Overflow
Update your code to assign your prototype to the Error.prototype and the instanceof and your asserts work. function NotImplementedError(message ...
Read more >
Custom errors, extending Error - The Modern JavaScript Tutorial
JavaScript allows to use throw with any argument, so technically our custom error classes don't need to inherit from Error .
Read more >
How to catch custom exception in a test that causes a DML ...
Data could be propagated to the test; It is not desirable to send email when testing; A custom exception is easier to test...
Read more >
A Comprehensive Guide To Error Handling In Node.js
Therefore, it is necessary to create custom error classes to better reflect the types of errors that could occur in your application.
Read more >
16 Handling Exceptions Using SOAP Faults
This chapter describes how to handle exceptions that occur when a message is being ... To use modeled faults, you need to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found