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

lib/querystring: convert to using internal/errors #15565

Merged
merged 1 commit into from Oct 28, 2017

Conversation

@ramimoshe
Contributor

ramimoshe commented Sep 23, 2017

covert lib/querystring.js over to using lib/internal/errors.js

ref: #11273

@BridgeAR

This needs a test and the error type should not change.

Show outdated Hide outdated lib/querystring.js
@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR

BridgeAR Sep 23, 2017

Member

@ramimoshe Thanks a lot for your PR! This goes in the right direction and just needs a bit more work 😃

Member

BridgeAR commented Sep 23, 2017

@ramimoshe Thanks a lot for your PR! This goes in the right direction and just needs a bit more work 😃

@refack refack self-assigned this Sep 23, 2017

@ramimoshe

This comment has been minimized.

Show comment
Hide comment
@ramimoshe

ramimoshe Sep 23, 2017

Contributor

thanks,
I changed the error to be ERR_INVALID_URL, and I did a small refactor

Contributor

ramimoshe commented Sep 23, 2017

thanks,
I changed the error to be ERR_INVALID_URL, and I did a small refactor

@refack

This comment has been minimized.

Show comment
Hide comment
@refack

refack Sep 23, 2017

Member

Thanks for following up.
Now all that's left is to fix the tests:

/^URIError: URI malformed$/);

/^URIError: URI malformed$/);

// invalid surrogate pair throws URIError
assert.throws(function() {
qs.stringify({ foo: '\udc00' });
}, /^URIError: URI malformed$/);

with something like:

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'
});

I did a small refactor

👍

Member

refack commented Sep 23, 2017

Thanks for following up.
Now all that's left is to fix the tests:

/^URIError: URI malformed$/);

/^URIError: URI malformed$/);

// invalid surrogate pair throws URIError
assert.throws(function() {
qs.stringify({ foo: '\udc00' });
}, /^URIError: URI malformed$/);

with something like:

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'
});

I did a small refactor

👍

if (i < str.length)
c2 = str.charCodeAt(i) & 0x3FF;
else
throw new URIError('URI malformed');

This comment has been minimized.

@lpinca

lpinca Sep 24, 2017

Member

I'm not sure if this should to be changed to use internal/errors. URIError seems fine to me.

@lpinca

lpinca Sep 24, 2017

Member

I'm not sure if this should to be changed to use internal/errors. URIError seems fine to me.

This comment has been minimized.

@BridgeAR

BridgeAR Sep 25, 2017

Member

I would definitely recommend to change this to use internal/errors but it should be kept as URIError as I mentioned above (#15565 (comment)).

@BridgeAR

BridgeAR Sep 25, 2017

Member

I would definitely recommend to change this to use internal/errors but it should be kept as URIError as I mentioned above (#15565 (comment)).

@ramimoshe

This comment has been minimized.

Show comment
Hide comment
@ramimoshe

ramimoshe Sep 24, 2017

Contributor

@refack
I am not sure how to update 'decodeURIComponent' function
so "node/test/parallel/test-querystring.js Lines 273 to 276 " test is still checking URIError

 // 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)
Contributor

ramimoshe commented Sep 24, 2017

@refack
I am not sure how to update 'decodeURIComponent' function
so "node/test/parallel/test-querystring.js Lines 273 to 276 " test is still checking URIError

 // 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)
@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR

BridgeAR Sep 25, 2017

Member

@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.

Member

BridgeAR commented Sep 25, 2017

@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.

@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR
Member

BridgeAR commented Sep 30, 2017

Ping @ramimoshe

@ramimoshe

This comment has been minimized.

Show comment
Hide comment
@ramimoshe

ramimoshe Sep 30, 2017

Contributor

Thank for your comments
but I am not fully understand you
@BridgeAR @refack do you mean to add "URIError" to module.exports in internal/errors?
e.g:

module.exports = exports = {
  message,
  URIError, 
  ....

or using the exported Error with URIError
e.g:

throw new errors.Error(URIError)
Contributor

ramimoshe commented Sep 30, 2017

Thank for your comments
but I am not fully understand you
@BridgeAR @refack do you mean to add "URIError" to module.exports in internal/errors?
e.g:

module.exports = exports = {
  message,
  URIError, 
  ....

or using the exported Error with URIError
e.g:

throw new errors.Error(URIError)
@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR

BridgeAR Sep 30, 2017

Member

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');
Member

BridgeAR commented Sep 30, 2017

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');
@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung

joyeecheung Oct 8, 2017

Member

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)

Member

joyeecheung commented Oct 8, 2017

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)

@refack

refack approved these changes Oct 8, 2017

@refack

This comment has been minimized.

Show comment
Hide comment
@refack

refack Oct 8, 2017

Member

I couldn't find a reference in the ECMAScript spec (image because the spec takes a while to load)
image


The Web IDL spec only excludes SyntaxError - https://heycam.github.io/webidl/#idl-exceptions

image

Member

refack commented Oct 8, 2017

I couldn't find a reference in the ECMAScript spec (image because the spec takes a while to load)
image


The Web IDL spec only excludes SyntaxError - https://heycam.github.io/webidl/#idl-exceptions

image

@refack

This comment has been minimized.

Show comment
Hide comment
@refack

refack Oct 8, 2017

Member

@ramimoshe, sorry for the delay.

so "node/test/parallel/test-querystring.js Lines 273 to 276 " test is still checking URIError

Use common.expectsError, specifying the type and code. Example

common.expectsError(
() => zlib.deflateSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView'
}
);

Member

refack commented Oct 8, 2017

@ramimoshe, sorry for the delay.

so "node/test/parallel/test-querystring.js Lines 273 to 276 " test is still checking URIError

Use common.expectsError, specifying the type and code. Example

common.expectsError(
() => zlib.deflateSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView'
}
);

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung

joyeecheung Oct 14, 2017

Member

@refack IMO

Indicates that one of the global URI handling functions was used in a way that is incompatible with its definition.

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.

Member

joyeecheung commented Oct 14, 2017

@refack IMO

Indicates that one of the global URI handling functions was used in a way that is incompatible with its definition.

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.

@joyeecheung

This would need to update test/parallel/test-querystring.js tests in order to pass the tests...

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung

joyeecheung Oct 14, 2017

Member

Also, test/parallel/test-querystring-escape.js needs to be updated as well.

Member

joyeecheung commented Oct 14, 2017

Also, test/parallel/test-querystring-escape.js needs to be updated as well.

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@ramimoshe

This comment has been minimized.

Show comment
Hide comment
@ramimoshe
Contributor

ramimoshe commented Oct 19, 2017

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung

joyeecheung Oct 19, 2017

Member

@ramimoshe Nope, looks like a flake because the failing test should not go through the query string module.

Member

joyeecheung commented Oct 19, 2017

@ramimoshe Nope, looks like a flake because the failing test should not go through the query string module.

@ramimoshe

This comment has been minimized.

Show comment
Hide comment
@ramimoshe

ramimoshe Oct 25, 2017

Contributor

@joyeecheung do i have to do something or just wait to approving?

Contributor

ramimoshe commented Oct 25, 2017

@joyeecheung do i have to do something or just wait to approving?

@joyeecheung joyeecheung dismissed stale reviews from BridgeAR and themself Oct 25, 2017

Fixed

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung

joyeecheung Oct 25, 2017

Member

@ramimoshe This is semver-major so needs at least 2 TSC approvals... @nodejs/tsc

Member

joyeecheung commented Oct 25, 2017

@ramimoshe This is semver-major so needs at least 2 TSC approvals... @nodejs/tsc

@jasnell jasnell added this to In Progress in Error Codes Oct 25, 2017

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung
Member

joyeecheung commented Oct 28, 2017

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung

joyeecheung Oct 28, 2017

Member

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.

Member

joyeecheung commented Oct 28, 2017

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.

@ramimoshe

This comment has been minimized.

Show comment
Hide comment
@ramimoshe

ramimoshe Oct 28, 2017

Contributor

@joyeecheung - yes, i will fix it

Contributor

ramimoshe commented Oct 28, 2017

@joyeecheung - yes, i will fix it

querystring: convert to using internal/errors
PR-URL: #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>

@refack refack merged commit 9788e96 into nodejs:master Oct 28, 2017

@refack

This comment has been minimized.

Show comment
Hide comment
@refack

refack Oct 28, 2017

Member

@ramimoshe Thanks!

Member

refack commented Oct 28, 2017

@ramimoshe Thanks!

@targos targos moved this from In Progress to Done in Error Codes Oct 29, 2017

Qard added a commit to ayojs/ayo that referenced this pull request Nov 2, 2017

querystring: convert to using internal/errors
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>

Qard added a commit to ayojs/ayo that referenced this pull request Nov 2, 2017

querystring: convert to using internal/errors
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>

addaleax added a commit to ayojs/ayo that referenced this pull request Dec 7, 2017

querystring: convert to using internal/errors
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>

@refack refack removed their assignment Oct 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment