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

errors,tls_wrap: migrate to use internal/errors.js #13476

Merged
merged 1 commit into from
Jul 19, 2017

Conversation

bidipyne
Copy link
Contributor

@bidipyne bidipyne commented Jun 5, 2017

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

tls_wrap.js, internal/errors.js

I read and understood the contribution guidelines, please review and suggest.
@jasnell
Thanks.

@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. tls Issues and PRs related to the tls subsystem. labels Jun 5, 2017
@@ -154,12 +157,21 @@ E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
E('ERR_UNKNOWN_SIGNAL', (signal) => `Unknown signal: ${signal}`);
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
E('ERR_RENEGOTIATE', 'Failed to renegotiate');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code should likely be a bit more specific... e.g. ERR_TLS_RENEGOTIATION_FAILED, etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -154,12 +157,21 @@ E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
E('ERR_UNKNOWN_SIGNAL', (signal) => `Unknown signal: ${signal}`);
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
E('ERR_RENEGOTIATE', 'Failed to renegotiate');
E('ERR_REQD_SERVER_NAME',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERR_TLS_SERVER_NAME_REQUIRED

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -54,7 +54,7 @@ function test(size, err, next) {
client.on('error', function(e) {
nerror++;
assert.strictEqual(e.message,
'DH parameter size 1024 is less than 2048');
'ERR_DH_PARAM_SIZE');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would need to be

assert.strictEqual(e.code, 'ERR_DH_PARAM_SIZE');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file, e is of type Object Error. This doesn't have the field e.code which we can access, so I believe, this one will be more appropriate in that case.

I have written a small test-case and verified that:

var u = require('util')
var e = new Error('ERR_DH_PARAM_SIZE');
console.log(u.inspect(e, {showHidden: true}))`

Output:

 at Object.<anonymous> (/home/bidisha/swe_node/n1/node/foo.js:2:9)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
  [stack]: 'Error: ERR_DH_PARAM_SIZE\n    at Object.<anonymous> (/home/bidisha/swe_node/n1/node/foo.js:2:9)\n    at Module._compile (module.js:569:30)\n    at Object.Module._extensions..js (module.js:580:10)\n    at Module.load (module.js:503:32)\n    at tryModuleLoad (module.js:466:12)\n    at Function.Module._load (module.js:458:3)\n    at Function.Module.runMain (module.js:605:10)\n    at startup (bootstrap_node.js:158:16)\n    at bootstrap_node.js:575:3',
  [message]: 'ERR_DH_PARAM_SIZE' }`

Please suggest on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the incorrect observation above.
Now, things seems to be resolved.
Thanks!

@@ -154,12 +157,21 @@ E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
E('ERR_UNKNOWN_SIGNAL', (signal) => `Unknown signal: ${signal}`);
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
E('ERR_RENEGOTIATE', 'Failed to renegotiate');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running');
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
E('ERR_TLS_SESSION_CALLBACK', 'TSL sesssion callback was called 2 times');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 'ERR_TLS_SESSION_CALLBACK_ALREADY_CALLED'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
Thank You!

E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
E('ERR_TLS_SESSION_CALLBACK', 'TSL sesssion callback was called 2 times');
E('ERR_TLS_OCSP_CALLBACK', 'TLS OCSP callback was called 2 times');
E('ERR_TLS_SNI_CALLBACK', 'TLS SNI callback was called 2 times');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add "_ALREADY_CALLED" to these 2 as well. It does make the code long but it also makes it clearer what's going wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/_tls_wrap.js Outdated
@@ -552,7 +553,7 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
}
if (!this._handle.renegotiate()) {
if (callback) {
process.nextTick(callback, new Error('Failed to renegotiate'));
process.nextTick(callback, new errors.Error('ERR_RENEGOTIATE'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ERR_RENEGOTIATE/ERR_TLS_RENEGOTIATE ?

lib/_tls_wrap.js Outdated
@@ -949,7 +950,7 @@ Server.prototype.setOptions = function(options) {
// SNI Contexts High-Level API
Server.prototype.addContext = function(servername, context) {
if (!servername) {
throw new Error('"servername" is required parameter for Server.addContext');
throw new errors.Error('ERR_REQD_SERVER_NAME');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ERR_REQD_SERVER_NAME/ERR_TLS_REQUIRED_SERVER_NAME ?

lib/_tls_wrap.js Outdated
@@ -1088,8 +1089,7 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
// specified in options.
var ekeyinfo = socket.getEphemeralKeyInfo();
if (ekeyinfo.type === 'DH' && ekeyinfo.size < options.minDHSize) {
var err = new Error('DH parameter size ' + ekeyinfo.size +
' is less than ' + options.minDHSize);
var err = new errors.Error('ERR_DH_PARAM_SIZE');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ERR_DH_PARAM_SIZE/ERR_TLS_DH_PARAM_SIZE ?

@@ -115,6 +115,7 @@ E('ERR_ASSERTION', (msg) => msg);
E('ERR_CONSOLE_WRITABLE_STREAM',
(name) => `Console expects a writable stream instance for ${name}`);
E('ERR_CPU_USAGE', (errMsg) => `Unable to obtain cpu usage ${errMsg}`);
E('ERR_DH_PARAM_SIZE', 'DH parameter size 1024 is less than 2048');
Copy link
Member

@jasnell jasnell Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hard coding the param size. it shouldn't be.

E('ERR_DH_PARAM_SIZE', (size) => `DH parameter size ${size} is less than 2048`);

E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
E('ERR_TLS_SESSION_CALLBACK_ALREADY_CALLED',
'TSL sesssion callback was called 2 times');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would take the opportunity to reword this a bit:

'The session callback was called more than once'

E('ERR_TLS_SESSION_CALLBACK_ALREADY_CALLED',
'TSL sesssion callback was called 2 times');
E('ERR_TLS_OCSP_CALLBACK_ALREADY_CALLED',
'TLS OCSP callback was called 2 times');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... making this a generic error would make more sense, e.g.

E('ERR_MULTIPLE_CALLBACK',
    (name) => `The ${name} callback was called more than once`);

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting closer but left a few comments that need to be addressed. Thank you!

@bidipyne bidipyne force-pushed the my-branch branch 2 times, most recently from cacf0d9 to bec79c7 Compare June 25, 2017 13:49
@bidipyne
Copy link
Contributor Author

Your suggestions are addressed.
Thank You! @jasnell

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jun 26, 2017
@mhdawson
Copy link
Member

Needs a rebase and then we can land.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -178,8 +178,29 @@ E('ERR_TRANSFORM_WITH_LENGTH_0',
E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s');
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
<<<<<<< 3129b2c035a1fb9b1bf07e5ecddcebce4c5fa4b0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a merge problem here. @bidipyne can you take a look/fix up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done that fix. Thanks @mhdawson

@bidipyne bidipyne force-pushed the my-branch branch 2 times, most recently from de7f1f7 to dbe7f78 Compare July 7, 2017 18:18
Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (except for the leaked lines in errors.js)

E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' +
'See https://github.com/nodejs/node/wiki/Intl');
E('FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rebase leak...
Could you go over this list and keep only the ERRs you need for this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all unrelated ERRs to this PR. Thanks! @refack.

@gireeshpunathil
Copy link
Member

`DH parameter size ${size} is less than 2048`);
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
E('ERR_MULTIPLE_CALLBACK',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a redefinition of ERR_MULTIPLE_CALLBACK from L162 this causes the error message to change.

  1. You can just remove this one and use the one in L162
  2. You can remove this one and improve L162 (and update its usages)
  3. [Optional] You could sort this whole block alphabetically (very easy if your IDE supports that, otherwise ignore)
  4. You can open an issue that E() doesn't fail for redefinition, or even better a PR that makes it fail 😉
not ok 1108 parallel/test-stream-transform-callback-twice
  ---
  duration_ms: 0.61
  severity: fail
  stack: |-
    assert.js:55
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 'The undefined callback was called more than once' === 'Callback called multiple times'
        at Transform.<anonymous> (/data/iojs/build/workspace/node-test-commit-linuxone/nodes/rhel72-s390x/test/common/index.js:716:14)
        at emitOne (events.js:115:13)
        at Transform.emit (events.js:210:7)
        at Transform.afterTransform (_stream_transform.js:80:17)
        at Transform.transform [as _transform] (/data/iojs/build/workspace/node-test-commit-linuxone/nodes/rhel72-s390x/test/parallel/test-stream-transform-callback-twice.js:5:37)
        at Transform._read (_stream_transform.js:185:10)
        at Transform._write (_stream_transform.js:173:12)
        at doWrite (_stream_writable.js:371:12)
        at writeOrBuffer (_stream_writable.js:357:5)
        at Transform.Writable.write (_stream_writable.js:274:11)
  ...

https://ci.nodejs.org/job/node-test-commit-linuxone/7151/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @refack
I have redefined the error message accordingly but this lead to change of another test file: test-stream-transform-callback-twice.js
Hope that is fine with this PR.
Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to test-stream-transform-callback-twice.js is good by me, but IMHO you should just remote L162, since this line simply overrides it anyway (there's no other magic).

`DH parameter size ${size} is less than 2048`);
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
E('ERR_MULTIPLE_CALLBACK',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to test-stream-transform-callback-twice.js is good by me, but IMHO you should just remote L162, since this line simply overrides it anyway (there's no other magic).

@@ -159,7 +159,7 @@ E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected');
E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe');
E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks');
E('ERR_MISSING_ARGS', missingArgs);
E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
E('ERR_MULTIPLE_CALLBACK', 'The undefined callback was called more than once');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right to me. 'The undefined callback...'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reverted the message back back. Please have a look!

E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
E('ERR_MULTIPLE_CALLBACK',
(name) => `The ${name} callback was called more than once`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my comment above. Agree with @refack that the duplicate line above needs to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

@@ -7,7 +7,7 @@ const stream = new Transform({

stream.on('error', common.expectsError({
type: Error,
message: 'Callback called multiple times',
message: 'The undefined callback was called more than once',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not be updating the code that generates this error so that it does not have 'undefined' but an indication of what the callback is ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referring to the suggestions above, error message on this file is also redefined.
Please suggest me on that!
Thank You! @mhdawson

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close just a few more comments.

@bidipyne
Copy link
Contributor Author

Thank you all, for guiding me on this PR @mhdawson @refack @jasnell @gireeshpunathil
As this PR is hanging there for a long time, it would be really helpful if I can get all the reviews altogether at once in order to make appropriate changes, making things easier to get it landed soon.

@refack refack self-assigned this Jul 16, 2017
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
E('ERR_TLS_RENEGOTIATION_FAILED', 'Failed to renegotiate');
E('ERR_TLS_REQUIRED_SERVER_NAME',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only remaining thing I see here is making sure that the error codes are in alphabetical order.

@refack
Copy link
Contributor

refack commented Jul 17, 2017

@bidipyne non-blocking observation. You changed 15 Error generating LOCs, and added 6 new Error codes, but fixed only 3 tests.
Do you have an idea how could we find the other impacted tests? They probably use unanchored RegExps (without start of line ^ and end on line $) so they still pass...
We should open a tracking issue with all those cases.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once order of messages is fixed. Please comment when you have done that and we can start the CI.

PR-URL: nodejs#13476
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
@refack refack merged commit f67aa56 into nodejs:master Jul 19, 2017
@refack
Copy link
Contributor

refack commented Jul 19, 2017

Addressed nit and landed
Extra sanity on master: https://ci.nodejs.org/job/node-test-commit-linuxone/7440/nodes=rhel72-s390x/

@refack refack removed their assignment Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. semver-major PRs that contain breaking changes and should be released in the next major version. tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants