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

node 9 loses error call site information in Buffer.concat #16994

Closed
reviewher opened this issue Nov 13, 2017 · 6 comments
Closed

node 9 loses error call site information in Buffer.concat #16994

reviewher opened this issue Nov 13, 2017 · 6 comments
Labels
good first issue Issues that are suitable for first-time contributors.

Comments

@reviewher
Copy link

  • Version: node 9.1.0
  • Platform: darwin
var f = (function () {
});
var g = (function() {
	Buffer.concat([new Buffer(3), f]);
});
g();

This results in an error. Using node 8.9.1, the error message clearly indicates that the problem is in the source:

buffer.js:444
      throw new TypeError(kConcatErrMsg);
      ^

TypeError: "list" argument must be an Array of Buffer or Uint8Array instances
    at Function.Buffer.concat (buffer.js:444:13)
    at g (/tmp/t.js:4:9) <--- notice the reference to t.js here, this is expected
    at Object.<anonymous> (/tmp/t.js:6:1)
    at Module._compile (module.js:635:30)

In node 9.1.0, the error message appears to come from the core:

buffer.js:475
      throw kConcatErr;
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "list" argument must be one of type array, buffer, or uint8Array
    at buffer.js:450:20
    at NativeModule.compile (bootstrap_node.js:601:7)
    at NativeModule.require (bootstrap_node.js:546:18)
    at util.js:26:22
    at NativeModule.compile (bootstrap_node.js:601:7)
    at Function.NativeModule.require (bootstrap_node.js:546:18)
    at setupGlobalVariables (bootstrap_node.js:263:31)
    at startup (bootstrap_node.js:32:5)
    at bootstrap_node.js:613:3 
@apapirovski
Copy link
Member

ERR_INVALID_ARG_TYPE clearly indicates that the error is with the code that's passing the wrong type of an argument.

https://nodejs.org/api/errors.html#errors_err_invalid_arg_type

@apapirovski
Copy link
Member

(That said, I understand that the stack trace could be better.)

@apapirovski
Copy link
Member

apapirovski commented Nov 13, 2017

Looks like we need to not predefine the error as it loses the stack trace information.

node/lib/buffer.js

Lines 450 to 452 in 1601a3c

const kConcatErr = new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'list', ['Array', 'Buffer', 'Uint8Array']
);

Labeling as good first issue and happy to assist anyone that wants to fix.

@apapirovski apapirovski added good first issue Issues that are suitable for first-time contributors. mentor-available labels Nov 13, 2017
@reviewher
Copy link
Author

The relevant PR that made the shift from the old style (generating an error in call site) to the new one (precomputing error) is #13976 , which references the general migration #11273

The notes https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md don't give any comments on preserving error stack, so maybe this is intentional behavior?

ping @jasnell @starkwang

@apapirovski
Copy link
Member

apapirovski commented Nov 13, 2017

Definitely not intentional. I think it was just an oversight. The error format should remain but it should be generated in the call site.

@ah-yu
Copy link
Contributor

ah-yu commented Nov 14, 2017

I'd like to fix it

MylesBorins pushed a commit that referenced this issue Dec 12, 2017
PR-URL: #17021
Fixes: #16994
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants