Throw custom error class is not propagated properly to the Queue
See original GitHub issueHi, 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.
I hope that the issue is clear, if not, I’m available for more details.
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mattwynne I am not super positive about this idea but I may change my opinion in the future.
@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.