url: port WHATWG URL API to internal/errors#12574
url: port WHATWG URL API to internal/errors#12574TimothyGu wants to merge 3 commits intonodejs:masterfrom
Conversation
doc/api/errors.md
Outdated
There was a problem hiding this comment.
This can also be just ERR_INVALID_ARG_TYPE with Iterable as the expected type..no strong feelings about it though.
There was a problem hiding this comment.
For this I think the more specific error is warranted.
lib/internal/url.js
Outdated
There was a problem hiding this comment.
I know the name/value thing is already in error messages...but since we are changing error messages anyway, I think [name, value] would be easier to understand at the first glance.
doc/api/errors.md
Outdated
There was a problem hiding this comment.
The "limited to WHATWG URL" part can be left out IMO, the source of errors would be visible in the stack trace anyway... This way people don't need to change this section when they add this type of error to other APIs
doc/api/errors.md
Outdated
There was a problem hiding this comment.
[name, value] tuple would be easier to grasp..
There was a problem hiding this comment.
"name/value tuple" is the WHATWG nomenclature, but I'm perfectly fine with "[name, value] tuple".
doc/api/errors.md
Outdated
There was a problem hiding this comment.
Note that at the moment input might not be exactly the same as the original input since it needs to go through trimming and String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8 first...we could've stored the original input, but that's for another PR to consider
There was a problem hiding this comment.
Right, the REPLACE_INVALID_UTF8 is pretty edge-case, but trimming can indeed be something the user does not expect. Agreed on addressing this in a separate PR though.
doc/api/errors.md
Outdated
There was a problem hiding this comment.
In that case, why not just use 'ERR_INVALID_ARG_TYPE'?
There was a problem hiding this comment.
'ERR_INVALID_ARG_TYPE' has the following templated message:
The "FOO" argument must be of type BAR.
In this case, it is not the question of what type the argument is, but whether it is defined at all.
lib/internal/errors.js
Outdated
There was a problem hiding this comment.
Maybe surround this with quotes or backticks? The original error message uses backticks.
There was a problem hiding this comment.
It's quite rare to have an error message with backticks in it (most error messages use double quotes). Here are a few alternatives:
- Value of "this" must be of type %s
- Method called on incompatible receiver of type %s (V8-inspired)
- Method called on incompatible %s (SpiderMonkey-inspired)
Choice 1 SGTM.
lib/internal/errors.js
Outdated
There was a problem hiding this comment.
I think undefined should be in the message here..otherwise if the user makes a mistake and passes an undefined, there is no way to know if it is an undefined or just an empty string.
lib/internal/url.js
Outdated
There was a problem hiding this comment.
It's a bit weird to put the verbs in separate places...maybe the must part can be left out in the error message format and written here?
test/common.js
Outdated
There was a problem hiding this comment.
Or maybe err instanceof code.constructor ?
There was a problem hiding this comment.
I don't know about this one, I'm generally not a huge fan of instanceof checks due to unreliability across different V8 contexts, and it is quite possible that WPT's testharness.js uses the error name string check instead of instanceof.
jasnell
left a comment
There was a problem hiding this comment.
I'd like to see @joyeecheung's comments addressed.
Also slightly revise the grammar of two-expected value scenario.
|
Addressed most of @joyeecheung's comments, except those that are still visible above. |
|
Landed in d457a98. |
Refs: #11273
Refs: #11299
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
url, errors