-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
errors, process: port internal/process errors to internal/errors #11294
Conversation
<a id="ERR_INVALID_ARG_TYPE"></a> | ||
### ERR_INVALID_ARG_TYPE | ||
|
||
The `'ERR_INVALID_ARG_TYPE'` error code is used generically to identify that |
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.
(Not sure which PR is the right place to ask, this one seems the oldest so I'll ask here)
Which one does the "type" here cover:
- Primitive types (i.e.
typeof
types, doesn't differentiateDate
andRegExp
and stuff) - Builtin type tags(i.e. results of
Object.prototype.toString.call()
, differentiatesDate
andRegExp
) - Class mismatch(i.e.
instanceof
types, differentiatesDate
andRegExp
)
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.
Also, some PRs use the typeof
types as the expected
type(e.g. "function"), some uses the class name/type tag(e.g. "Object"), we probably need to be a little bit consistent on this one.
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 is not handled very consistently throughout the Node.js source. Sometimes the value itself is passed in, sometimes the typeof is used, etc. The goal here would be to start getting some consistency but it's hard to nail down exactly what that should be.
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.
Got it, so we should focus on migrating the errors to use the new system with a reasonable code
right now, and deal with message
later, because after the migration it would be easier to change them anyway?
lib/internal/errors.js
Outdated
msg += `one of type ${expected.slice(0, len - 1).join(', ')}, or ` + | ||
expected[len - 1]; | ||
} else { | ||
msg += `type ${String(expected[0])}`; |
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.
String(..)
seems unnecessary here?
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.
+1. It's already cast on line 103
18670e4
to
e24a450
Compare
@nodejs/ctc ... as a semver major this needs some review and signoff |
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.
@jasnell in the invalidArgType : what if the actual arg is null , the result will be . Received type object
Sigh, good point. I often forget that typeof null === 'object' which is really quite odd. |
e24a450
to
1727832
Compare
lib/internal/errors.js
Outdated
E('ERR_INVALID_CALLBACK', 'callback must be a function'); | ||
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed'); | ||
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed'); | ||
E('ERR_UNK_STDIN_TYPE', 'Unknown stdin file type'); |
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.
#11298 spells the full UNKNOWN
, this should do the same (TBH I can not understand what UNK
stands for at first glance...).
7f1def6
to
86c7993
Compare
@nodejs/ctc ... PTAL... I'd like to get this landed so we can start getting through the others that are starting to stack up |
86c7993
to
9d3c44f
Compare
ping @evanlucas, @addaleax, @cjihrig and @mhdawson |
As I mentioned somewhere else (not sure where, there have been a bunch of these pull requests), I'm not thrilled with what the stack trace looks like after this change. |
Which part are you unhappy with? |
$ ./node --expose-internals
> new errors.Error('ERR_ASSERTION', 'something')
{ Error[ERR_ASSERTION]: something
at repl:1:1
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:433:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:262:10)
at REPLServer.Interface._line (readline.js:611:8) [Symbol(code)]: 'ERR_ASSERTION' } I just find it a little harder to read |
Do you have an alternative suggestion? Displaying the error code in the output is a significant reason why this allows us to avoid treating changes in the error message as semver-major... That is, it gives the user a stable, non-changing key they can use to search for information on the specific error. Putting the |
I can't find it either, but I chimed in on that too. If @evanlucas's output is accurate, the |
The > var m = new Error("test")
undefined
> m.code = 1
1
> m
{ Error: test
at repl:1:9
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:433:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:262:10)
at REPLServer.Interface._line (readline.js:611:8) code: 1 } I will open a PR that adds the space before the opening |
PR: #12099 |
Ping @nodejs/ctc ... I'd like to get this landed. Before the other errors ones get landed. |
@jasnell This needs at least one more CTC approval before landing. Maybe you can horse-trade with @trevnorris: You review his async-hooks PR that he's not getting enough reviews on and in return he reviews this. I'm kidding. Or am I? |
I'd review the async-hooks had I the time. It's a large pr. I can take a look next week. There are quite a few other prs pending on this one, all semver major, that I would like to get landed |
var len = expected.length; | ||
expected = expected.map((i) => String(i)); | ||
if (len > 1) { | ||
msg += `one of type ${expected.slice(0, len - 1).join(', ')}, or ` + |
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.
Maybe break out the expected.slice().join()
into a variable? It is getting a little hard to read imo.
} else { | ||
msg += `of type ${String(expected)}`; | ||
} | ||
if (arguments.length >= 3) { |
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.
With only the first three arguments being used, maybe make this if (arguments.length === 3) {
?
Feel free to disregard
@evanlucas ... do you still object to this? |
@jasnell my review was not an objection. I think I'm onboard with this now. |
Awesome, ok. Can I ask you to switch the "requested changes" to an approval or LGTM so I can get this landed. As a semver-major I need two CTC signoffs :-) |
6ddc9a2
to
626332f
Compare
* Assign codes to the handful of errors reported by internal/process/*.js * Include documentation for the new error codes * Improve error messages * Improve test coverage for process.nextTick Ref: nodejs#11273
626332f
to
8dbce73
Compare
Final CI before landing: https://ci.nodejs.org/job/node-test-pull-request/7553/ |
CI failures are unrelated. Failures in CITGM are not specific to this PR. |
* Assign codes to the handful of errors reported by internal/process/*.js * Include documentation for the new error codes * Improve error messages * Improve test coverage for process.nextTick PR-URL: #11294 Ref: #11273 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
Landed in e75bc87 |
Ref: #11273
Semver-major because this updates specific error messages and converts errors over to use the new internal/errors.js mechanism.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
errors, process