-
Notifications
You must be signed in to change notification settings - Fork 391
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
Replace lodash methods #2454
Replace lodash methods #2454
Conversation
src/classes/main-base.ts
Outdated
@@ -35,7 +34,7 @@ export default ( | |||
|
|||
process.on('uncaughtException', async (err: Error) => { | |||
if (!err.message) { | |||
err = new Error(toString(err)); | |||
err = new Error(`${err}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect that err gets into this line so converting it as a string should be sufficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it is not really the same actually. As the issue here is that we do not know what err is. We are doing a lousy check to see if err contains a message, if not we just try to convert whatever err is to a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this event is only receiving Error objects https://nodejs.org/api/process.html#event-uncaughtexception, do we have another example when this is not true? If not looks like ${err}
will be sufficient 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but then why are we doing this:
if (!err.message)
If err is guaranteed an Error, then it should not be needed to do that check I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah agree, let me remove that check
8641889
to
abeb870
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good initiative. I think we need to think more about toString, or worst case implement a similar function ourselves.
src/classes/main-base.ts
Outdated
@@ -35,7 +34,7 @@ export default ( | |||
|
|||
process.on('uncaughtException', async (err: Error) => { | |||
if (!err.message) { | |||
err = new Error(toString(err)); | |||
err = new Error(`${err}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it is not really the same actually. As the issue here is that we do not know what err is. We are doing a lousy check to see if err contains a message, if not we just try to convert whatever err is to a string.
src/classes/job.ts
Outdated
@@ -44,7 +43,12 @@ const optsDecodeMap = { | |||
rdof: 'removeDependencyOnFailure', | |||
}; | |||
|
|||
const optsEncodeMap = invert(optsDecodeMap); | |||
const optsEncodeMap = Object.entries(optsDecodeMap).reduce< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be beneficial to refactor this code into a separate function (invertObject for example) so that we can more easily understand what this code is actually doing.
I wrote this simple experiment: process.on("uncaughtException", function (err) {
console.log("Caught exception: " + err);
console.log(err);
console.log(err.stack);
});
throw new Error("This will crash");
// throw ["This will crash too!"] It is actually not guaranteed that err will be an Error, it can be anything that has been thrown... so the correct signature should be:
Now, I do not know if there is a lot of value in using the lodash toString method anyway, as at least from BullMQ we should always make sure that we throw errors and not other things, however it is important to make this handler crash proof, but I think it is too with the new code. |
@@ -33,10 +32,7 @@ export default ( | |||
process.on('SIGTERM', () => childProcessor.waitForCurrentJobAndExit()); | |||
process.on('SIGINT', () => childProcessor.waitForCurrentJobAndExit()); | |||
|
|||
process.on('uncaughtException', async (err: Error) => { | |||
if (!err.message) { | |||
err = new Error(toString(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me a bit nervous, not sure if this is the correct thing to do. So if the error does not include .message we assume it is not an error object, but more likely just a string, and thus we create a new error here, which will create also an error stack. If we do not do this, then we call errorToJSON with a string , will this yield this a correct "value"? This uncaughException is emitted in userland code, out of our control... can we track who did add this code to see if we can understand the original intend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that this change was added last year with worker threads support 0820985#diff-dba50fb04784a53f9826c6cb96929de2d71329d82f1d97418a13fc54a955f8d5R37-R39
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that in order not to create a regression (even though no test is testing this feature), we should implement our own toString then if we want to get rid of lodash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, you did already 👍
No description provided.