| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
This needs a test and the error type should not change.
Sorry, something went wrong.
There was a problem hiding this comment.
The error type URIError should stay as it is. If that type does not yet exist in the internal/errors it has to be created.
Out of my perspective a better name for the internal type would also be ERR_INVALID_URI (I am still thinking about if it would be a good idea to combine this with the existing ERR_INVALID_URL type or not) and the error message itself should be moved in the internal errors as static value.
Sorry, something went wrong.
There was a problem hiding this comment.
As a temporary workaround this could be done with:
else {
const e = new URIError('URI malformed');
e.code = 'ERR_INVALID_URI';
throw e;
}
Sorry, something went wrong.
There was a problem hiding this comment.
Since this is the only place in /lib/ where URIError is used, I'm not sure it should not be changed...
/cc @jasnell
Sorry, something went wrong.
There was a problem hiding this comment.
This recommendation is bad out of my perspective. It is not similar to the internal/errors by just adding the error code. It is neither a NodeError, nor would it receive any further changes in case something changes in the internal/errors.
I would also like to keep the error type as URIError even if it is the only occurrence in lib. It is a single line that has to be added to the internal/errors to add that type and use it from then on.
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
|
@ramimoshe Thanks a lot for your PR! This goes in the right direction and just needs a bit more work 😃 |
Sorry, something went wrong.
|
thanks, |
Sorry, something went wrong.
There was a problem hiding this comment.
So we have a new lint rule that makes sure the error code are sorted in ASCIIbetical order.
It would have made you notice https://github.com/nodejs/node/blob/4518d94e6104323b06781ba608e59208d35a6129/lib/internal/errors.js#L243
So IMHO make this ERR_INVALID_URI (so that we can keep the message text the same), and move it to L243 above the previous ERR_INVALID_URL
Sorry, something went wrong.
|
Thanks for following up. common.expectsError(
() => qs.stringify({ foo: '\udc00' }),
{
code: 'ERR_INVALID_URI',
type: TypeError,
message: 'URI malformed'
}
);or just as the validator for assert.throws common.expectsError({
code: 'ERR_INVALID_URI',
type: TypeError,
message: 'URI malformed'
});
👍 |
Sorry, something went wrong.
There was a problem hiding this comment.
I'm not sure if this should to be changed to use internal/errors. URIError seems fine to me.
Sorry, something went wrong.
There was a problem hiding this comment.
I would definitely recommend to change this to use internal/errors but it should be kept as URIError as I mentioned above (#15565 (comment)).
Sorry, something went wrong.
|
@refack // invalid surrogate pair throws URIError
assert.throws(function() {
qs.stringify({ foo: '\udc00' });
}, /^URIError: URI malformed$/); StackTrace from the test (after changing): URIError: URI malformed
at decodeURIComponent (<anonymous>)
at Url.parse (url.js:292:19)
at Object.urlParse [as parse] (url.js:98:5)
at Object.<anonymous> (/Users/rami.moshe/Projects/forks/node/test/parallel/test-url-parse-invalid-input.js:27:5)
at Module._compile (module.js:600:30)
at Object.Module._extensions..js (module.js:611:10)
at Module.load (module.js:521:32)
at tryModuleLoad (module.js:484:12)
at Function.Module._load (module.js:476:3)
at Function.Module.runMain (module.js:641:10)
|
Sorry, something went wrong.
|
@ramimoshe you can not update the decodeURIComponent function and you should not even try. It is a native function. The error type should definitely not be changed because it would be inconsistent in that case what error we might return. Please switch back to the URIError and just add that type to the internal/errors as I pointed out. |
Sorry, something went wrong.
|
Thank for your comments module.exports = exports = {
message,
URIError,
....or using the exported Error with URIError throw new errors.Error(URIError) |
Sorry, something went wrong.
|
This is how you can add the URIError to the internal/errors. module.exports = exports = {
message,
Error: makeNodeError(Error),
TypeError: makeNodeError(TypeError),
RangeError: makeNodeError(RangeError),
URIError: makeNodeError(URIError), // <----
AssertionError,
E // This is exported only to facilitate testing.
};And this is how you would use it in a different file. const errors = require('internal/errors');
// ...
throw new errors.URIError('ERR_INVALID_URI'); |
Sorry, something went wrong.
|
I think I have brought this up in a URL PR before but couldn't find the link. The ECMAScript spec says URIError should only be raised by built-in functions, i.e. functions like decodeURIComponent() that are implemented as part of the language, we should not raise that in our codebase anyway. (Going to board so no time to dig the link to spec) |
Sorry, something went wrong.
|
I couldn't find a reference in the ECMAScript spec (image because the spec takes a while to load) The Web IDL spec only excludes SyntaxError - https://heycam.github.io/webidl/#idl-exceptions |
Sorry, something went wrong.
|
@ramimoshe, sorry for the delay.
Use common.expectsError, specifying the type and code. Example node/test/parallel/test-zlib-not-string-or-buffer.js Lines 10 to 18 in b050c14 |
Sorry, something went wrong.
|
@refack IMO
means it excludes user land methods from throwing a URIError, because those are not "global URI handling functions". Also the WHATWG URL doesn't throw URIError either, it throws TypeError in similar situations. Anyway, I am still fine with throwing URIError in this PR because that's what we do at the moment. |
Sorry, something went wrong.
There was a problem hiding this comment.
This would need to update test/parallel/test-querystring.js tests in order to pass the tests...
Sorry, something went wrong.
|
Also, test/parallel/test-querystring-escape.js needs to be updated as well. |
Sorry, something went wrong.
Sorry, something went wrong.
|
@joyeecheung do you know the issue with ubuntu1404-64 build? |
Sorry, something went wrong.
|
@ramimoshe Nope, looks like a flake because the failing test should not go through the query string module. |
Sorry, something went wrong.
|
@joyeecheung do i have to do something or just wait to approving? |
Sorry, something went wrong.
|
@ramimoshe This is semver-major so needs at least 2 TSC approvals... @nodejs/tsc |
Sorry, something went wrong.
|
CI before landing: https://ci.nodejs.org/job/node-test-pull-request/11040/ |
Sorry, something went wrong.
|
https://ci.nodejs.org/job/node-test-linter/13033/console not ok 11 - /usr/home/iojs/build/workspace/node-test-linter/lib/internal/errors.js
---
message: '"ERR_INVALID_URI" is not documented in doc/api/errors.md'
severity: error
data:
line: 291
column: 1
ruleId: documented-errors
messages:
- message: doc/api/errors.md does not have an anchor for "ERR_INVALID_URI"
severity: error
data:
line: 291
column: 1
ruleId: documented-errors
...
@ramimoshe Do you have time to document this error code? If not I can do that, just don't want to delay this PR for too long. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM if CI is green: https://ci.nodejs.org/job/node-test-pull-request/11053/
Sorry, something went wrong.
PR-URL: nodejs#15565 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
PR-URL: nodejs/node#15565 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
PR-URL: nodejs/node#15565 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
PR-URL: nodejs/node#15565 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
| Back | FazBrowse Home | New Git URL |
covert lib/querystring.js over to using lib/internal/errors.js
ref: #11273