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
Merged

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.

lib/internal/errors.js Outdated
@@ -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');

This comment has been minimized.

@jasnell

jasnell Jun 5, 2017
Member

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

This comment has been minimized.

This comment has been minimized.

@bidipyne

bidipyne Jun 15, 2017
Author Contributor

Done!

lib/internal/errors.js Outdated
@@ -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',

This comment has been minimized.

@jasnell

jasnell Jun 5, 2017
Member

ERR_TLS_SERVER_NAME_REQUIRED

This comment has been minimized.

@bidipyne

bidipyne Jun 15, 2017
Author Contributor

Done!

test/parallel/test-tls-client-mindhsize.js Outdated
@@ -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');

This comment has been minimized.

@jasnell

jasnell Jun 5, 2017
Member

this would need to be

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

This comment has been minimized.

@bidipyne

bidipyne Jun 14, 2017
Author Contributor

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.

This comment has been minimized.

@bidipyne

bidipyne Jun 15, 2017
Author Contributor

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

lib/internal/errors.js Outdated
@@ -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');

This comment has been minimized.

lib/internal/errors.js Outdated
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');

This comment has been minimized.

@mhdawson

mhdawson Jun 6, 2017
Member

maybe 'ERR_TLS_SESSION_CALLBACK_ALREADY_CALLED'

This comment has been minimized.

@bidipyne

bidipyne Jun 15, 2017
Author Contributor

Done.
Thank You!

lib/internal/errors.js Outdated
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');

This comment has been minimized.

@mhdawson

mhdawson Jun 6, 2017
Member

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.

This comment has been minimized.

@bidipyne

bidipyne Jun 15, 2017
Author Contributor

Done.

@bidipyne bidipyne force-pushed the bidipyne:my-branch branch 2 times, most recently Jun 14, 2017
@bidipyne bidipyne closed this Jun 14, 2017
@bidipyne bidipyne force-pushed the bidipyne:my-branch branch to de762b7 Jun 14, 2017
@bidipyne bidipyne reopened this Jun 14, 2017
@bidipyne bidipyne force-pushed the bidipyne:my-branch branch 4 times, most recently Jun 14, 2017
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'));

This comment has been minimized.

@jasnell

jasnell Jun 15, 2017
Member

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

This comment has been minimized.

@jasnell

jasnell Jun 15, 2017
Member

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

This comment has been minimized.

@jasnell

jasnell Jun 15, 2017
Member

s/ERR_DH_PARAM_SIZE/ERR_TLS_DH_PARAM_SIZE ?

lib/internal/errors.js Outdated
@@ -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');

This comment has been minimized.

@jasnell

jasnell Jun 15, 2017
Member

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`);
lib/internal/errors.js Outdated
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');

This comment has been minimized.

@jasnell

jasnell Jun 15, 2017
Member

I would take the opportunity to reword this a bit:

'The session callback was called more than once'
lib/internal/errors.js Outdated
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');

This comment has been minimized.

@jasnell

jasnell Jun 15, 2017
Member

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

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

@bidipyne bidipyne force-pushed the bidipyne:my-branch branch 2 times, most recently Jun 25, 2017
@bidipyne
Copy link
Contributor Author

@bidipyne bidipyne commented Jun 25, 2017

Your suggestions are addressed.
Thank You! @jasnell

Copy link
Member

@jasnell jasnell left a comment

Thank you!

@mhdawson
Copy link
Member

@mhdawson mhdawson commented Jun 29, 2017

Needs a rebase and then we can land.

Copy link
Member

@mhdawson mhdawson left a comment

LGTM

@jasnell jasnell mentioned this pull request Jun 29, 2017
79 of 80 tasks complete
lib/internal/errors.js Outdated
@@ -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

This comment has been minimized.

@mhdawson

mhdawson Jul 7, 2017
Member

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

This comment has been minimized.

@bidipyne

bidipyne Jul 7, 2017
Author Contributor

Done that fix. Thanks @mhdawson

@bidipyne bidipyne force-pushed the bidipyne:my-branch branch 2 times, most recently Jul 7, 2017
Copy link
Member

@refack refack left a comment

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

lib/internal/errors.js Outdated
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');

This comment has been minimized.

@refack

refack Jul 7, 2017
Member

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

This comment has been minimized.

@bidipyne

bidipyne Jul 8, 2017
Author Contributor

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

@bidipyne bidipyne force-pushed the bidipyne:my-branch branch Jul 8, 2017
@refack
refack approved these changes Jul 8, 2017
@refack refack force-pushed the bidipyne:my-branch branch Jul 8, 2017
lib/internal/errors.js Outdated
`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',

This comment has been minimized.

@refack

refack Jul 8, 2017
Member

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/

This comment has been minimized.

@bidipyne

bidipyne Jul 8, 2017
Author Contributor

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!

This comment has been minimized.

@refack

refack Jul 8, 2017
Member

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

@bidipyne bidipyne force-pushed the bidipyne:my-branch branch Jul 8, 2017
@refack
refack approved these changes Jul 8, 2017
lib/internal/errors.js Outdated
`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',

This comment has been minimized.

@refack

refack Jul 8, 2017
Member

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

lib/internal/errors.js Outdated
@@ -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');

This comment has been minimized.

@mhdawson

mhdawson Jul 11, 2017
Member

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

This comment has been minimized.

@bidipyne

bidipyne Jul 16, 2017
Author Contributor

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

lib/internal/errors.js Outdated
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`);

This comment has been minimized.

@mhdawson

mhdawson Jul 11, 2017
Member

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

This comment has been minimized.

@bidipyne

bidipyne Jul 16, 2017
Author Contributor

Removed!

test/parallel/test-stream-transform-callback-twice.js Outdated
@@ -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',

This comment has been minimized.

@mhdawson

mhdawson Jul 11, 2017
Member

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 ?

This comment has been minimized.

@bidipyne

bidipyne Jul 16, 2017
Author Contributor

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

Very close just a few more comments.

@bidipyne bidipyne force-pushed the bidipyne:my-branch branch 2 times, most recently Jul 16, 2017
@bidipyne
Copy link
Contributor Author

@bidipyne bidipyne commented Jul 16, 2017

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
lib/internal/errors.js Outdated
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',

This comment has been minimized.

@jasnell

jasnell Jul 17, 2017
Member

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

@refack
Copy link
Member

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

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

PR-URL: #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 force-pushed the bidipyne:my-branch branch to f67aa56 Jul 19, 2017
@refack refack merged commit f67aa56 into nodejs:master Jul 19, 2017
1 check was pending
1 check was pending
test/linux-one running tests
Details
@refack
Copy link
Member

@refack 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 added this to Done in Error Codes Aug 20, 2017
@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
Projects
Error Codes
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.