-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 reporter bug when rejecting non-errors #1281
Conversation
Interesting find. I think the error comes from this line, really: Line 24 in 98dded5
Unhandled rejections are normalized: Line 72 in 98dded5
Perhaps the Line 59 in 98dded5
Long story short, this means errors have the expected shape in the reporters and we don't have to keep checking if certain properties are strings etc. @avajs/core thoughts? |
👍 |
@novemberborn thank you for the response. I think having |
@jakwuh yea. Though that's just for rejection reasons that aren't objects. We also need to sanitize objects with unexpected properties. |
@novemberborn here we go, now regardfully listening to any feedback :) |
lib/run-status.js
Outdated
if (isObj(err) && 'message' in err && typeof err.message === 'string') { | ||
['name', 'stack'].forEach(field => { | ||
if (field in err && typeof err[field] !== 'string') { | ||
delete err[field]; |
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 this really does need to go here:
Line 59 in 98dded5
if (err.stack) { |
We don't want to modify err
since it comes from user code. There may be side-effects. But we can't easily copy error objects since name
and message
aren't always enumerable. After the call to cleanYamlObject
in serialize-error.js
we have a copy we can safely modify.
Also, in this case, I'd prefer a little bit of duplication over your forEach
trick. IMHO this is a lot easier to follow:
if ('name' in err && typeof err.name !== 'string') {
delete err.name
}
if ('stack' in err && typeof err.stack !== 'string') {
delete err.stack
}
Even better, delete
only deletes own-properties, so the 'name' in err
guard is unnecessary.
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.
Yes, this totally makes sense, still I find fairly to say that errors coming to normalizeError
are already serialized (as I can see from the test-worker code).
Also thank you a lot for your fast and detailed feedback.
@novemberborn here we go 🙂 |
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.
Great!
@@ -20,6 +20,11 @@ function filter(propertyName, isRoot, source, target) { | |||
return true; | |||
} | |||
|
|||
if ((propertyName === 'name' || propertyName === 'stack') && | |||
typeof source[propertyName] !== '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.
@sindresorhus any thoughts on this? XO doesn't complain 😉
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.
Why should it have complained?
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.
Figured it may have opinions on if condition indenting.
Woot! Very good work @jakwuh :) |
Thanks 😊 |
To reproduce try ava with the following test: