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

Error "message" property enumerability change on 9.7.0+ #19716

Closed
alexjeffburke opened this issue Apr 1, 2018 · 5 comments
Closed

Error "message" property enumerability change on 9.7.0+ #19716

alexjeffburke opened this issue Apr 1, 2018 · 5 comments

Comments

@alexjeffburke
Copy link
Contributor

  • Version: 9.7.0+
  • Platform: macOS 10.12.6
  • Subsystem: errors

Background
There appears to be a change in the enumerability of the "message" property on at least errors coming up from the getaddrinfo system call that were noticed when a number of tests for the Unexpected project and a number of it's plugins started failing. After looking into and rolling out code changes I was able to beset node versions, and it seems this issue was introduced between 9.6.1 and 9.7.0.

The follwing code should demonstrate the issue:

const dns = require('dns');

dns.lookup('asdfasdfasdfasdfasdfasdfasdf.zzz', (err) => {
    if (!err) return;
    var enumerableKeys = Object.keys(err);
    var hasMessage = enumerableKeys.indexOf('message') > -1;
    console.log(`${err.name} with ${enumerableKeys.length} enumerable keys ${hasMessage ? 'WITH' : 'WITHOUT'} "message"`);
 });

Expected outcome
Both version of node report the same number of enumerable keys and message is not included.

Actual outcome
9.6.1: 'Error with 4 enumerable keys WITHOUT "message"'
9.7.0: 'Error with 5 enumerable keys WITH "message"'

Summary
I hope the above is enough to explain the issue. Based on the workaround we applied, it seems likely that these errors were previously instantiated by passing the message into the constructor but were changed so the message was attached after the fact.

If there's anything else I can provide please let me know.

Thanks

@mscdex
Copy link
Contributor

mscdex commented Apr 1, 2018

If I had to guess, it may be 1246902. One difference is that no message is being passed to the Error() constructor anymore, but the .message property is being manually set now. That might cause this change?

@joyeecheung
Copy link
Member

@alexjeffburke Yes that's the intended behavior, because most errors coming out of Node.js or the JS engine does not have a enumerable error.message since it's spec'ed that messages passed during instantiation should not be enumerable. Could not find a link but I believe transforming the errors into a more uniformed manner triggered a test failure because it didn't expect a message out of a child process printingJSON.stringify(err).

@joyeecheung
Copy link
Member

joyeecheung commented Apr 1, 2018

Also, to test against errors coming out of Node.js v8 and above, a better way is to test against (a subset of) their properties, e.g. syscall, code and host, instead of strictly matching against messages. That's also what we started to do in the tests of Node.js core.

@BridgeAR BridgeAR mentioned this issue Apr 1, 2018
4 tasks
@joyeecheung
Copy link
Member

joyeecheung commented Apr 1, 2018

Oops, I think I misread the OP, it was talking about dnsException, not uvException that I mentioned in #19716 (comment) , this should be fixed by #19719

@alexjeffburke
Copy link
Contributor Author

@mscdex yeah I think it is exactly that - within the commit you linked it's this ending up as that.

@joyeecheung yep it's a defined quirk in the spec. I know checking those properties or perhaps soon a standard error code is the more correct way, but pretty sure this change was unintentional and it does rather subtly change behaviour.

@BridgeAR thanks for jumping on it.

BridgeAR added a commit to BridgeAR/node that referenced this issue Apr 4, 2018
A error message should always be non-enumerable. This makes sure
that is true for dns errors as well. It also adds another check
in `common.expectsError` to make sure no other regressions are
introduced going forward.

Fixes nodejs#19716
BridgeAR added a commit to BridgeAR/node that referenced this issue May 1, 2018
A error message should always be non-enumerable. This makes sure
that is true for dns errors as well. It also adds another check
in `common.expectsError` to make sure no other regressions are
introduced going forward.

Fixes nodejs#19716

PR-URL: nodejs#19719
Fixes: nodejs#19716
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
joyeecheung pushed a commit to joyeecheung/node that referenced this issue May 2, 2018
A error message should always be non-enumerable. This makes sure
that is true for dns errors as well. It also adds another check
in `common.expectsError` to make sure no other regressions are
introduced going forward.

Fixes nodejs#19716

PR-URL: nodejs#19719
Fixes: nodejs#19716
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue May 22, 2018
A error message should always be non-enumerable. This makes sure
that is true for dns errors as well. It also adds another check
in `common.expectsError` to make sure no other regressions are
introduced going forward.

Fixes #19716

Backport-PR-URL: #19191
PR-URL: #19719
Fixes: #19716
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Jun 14, 2018
A error message should always be non-enumerable. This makes sure
that is true for dns errors as well. It also adds another check
in `common.expectsError` to make sure no other regressions are
introduced going forward.

Fixes #19716

Backport-PR-URL: #19191
PR-URL: #19719
Fixes: #19716
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
rvagg pushed a commit that referenced this issue Aug 16, 2018
A error message should always be non-enumerable. This makes sure
that is true for dns errors as well. It also adds another check
in `common.expectsError` to make sure no other regressions are
introduced going forward.

Fixes #19716

Backport-PR-URL: #19191
PR-URL: #19719
Fixes: #19716
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants