-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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');
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
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'); |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
47f3eff
to
9a86f6d
Compare
b7dcebb
to
45c9e10
Compare
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')); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 ?
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'); |
There was a problem hiding this comment.
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`);
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'); |
There was a problem hiding this comment.
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'
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'); |
There was a problem hiding this comment.
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`);
There was a problem hiding this 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!
cacf0d9
to
bec79c7
Compare
Your suggestions are addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Needs a rebase and then we can land. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
de7f1f7
to
dbe7f78
Compare
There was a problem hiding this 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)
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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', |
There was a problem hiding this comment.
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.
- You can just remove this one and use the one in L162
- You can remove this one and improve L162 (and update its usages)
- [Optional] You could sort this whole block alphabetically (very easy if your IDE supports that, otherwise ignore)
- 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)
...
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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).
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', |
There was a problem hiding this comment.
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).
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'); |
There was a problem hiding this comment.
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...'
There was a problem hiding this comment.
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!
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`); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this 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.
2b58918
to
32a6d1a
Compare
Thank you all, for guiding me on this PR @mhdawson @refack @jasnell @gireeshpunathil |
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', |
There was a problem hiding this comment.
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.
@bidipyne non-blocking observation. You changed 15 Error generating LOCs, and added 6 new Error codes, but fixed only 3 tests. |
There was a problem hiding this 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 <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Addressed nit and landed |
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
tls_wrap.js, internal/errors.js
I read and understood the contribution guidelines, please review and suggest.
@jasnell
Thanks.