-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Migrate _stream_readable errors to internal/errors #15042
Conversation
@jasnell I wasn't able to get the tests to pass...
my attempt...
|
Ping @nodejs/streams @mcollina |
As stated elsewhere, I'm very 👎 on this change until we have a clear strategy on how to keep the same behavior on |
@mcollina thanks for the feedback. |
Hello @benhalverson and welcome. Thank you for the contribution 🥇 I've marked it as |
lib/internal/errors.js
Outdated
E('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event'); | ||
E('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF'); | ||
E('ERR_UNDERSCORE_READ_NOT_IMPLEMENTED', '_read() is not implemented'); | ||
E('ERR_END_READABLE_CALLED_ON_NONEMPTY_STREAM', 'endReadable() called on a non-empty stream'); |
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.
Can you please put this in alphabetical order :-) thank you!
Also, I believe these need line wrapped at 80 chars. Run make lint
to check
lib/_stream_readable.js
Outdated
@@ -551,7 +552,7 @@ function maybeReadMore_(stream, state) { | |||
// for virtual (non-string, non-buffer) streams, "length" is somewhat | |||
// arbitrary, and perhaps not very meaningful. | |||
Readable.prototype._read = function(n) { | |||
this.emit('error', new Error('_read() is not implemented')); | |||
this.emit('error', new errors.Error('ERR_UNDERSCORE_READ_NOT_IMPLEMENTED')); |
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_UNDERSCORE_READ_NOT_IMPLEMENTED
/ERR_STREAM_READ_NOT_IMPLEMENTED
lib/_stream_readable.js
Outdated
@@ -1043,7 +1044,7 @@ function endReadable(stream) { | |||
// If we get here before consuming all the bytes, then that is a | |||
// bug in node. Should never happen. | |||
if (state.length > 0) | |||
throw new Error('"endReadable()" called on non-empty stream'); | |||
throw new errors.Error('ERR_END_READABLE_CALLED_ON_NONEMPTY_STREAM'); |
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_END_READABLE_CALLED_ON_NONEMPTY_STREAM
/ERR_STREAM_READABLE_CALLED_ON_NONEMPTY
To explain @refack's comments a bit more. The streams module in core is kept in sync with the standalone |
At the latest streams wg we decided to unblock this. We would like this (and the equals for Writable, Duplex and Transform) to ship in Node 9. |
@benhalverson I think you can use See https://github.com/nodejs/node/blob/c2e838ee13244dd3dbd98ed86ef1966fe7cd90f1/test/parallel/test-require-invalid-package.js as an example. |
Thanks @mcollina I'll take a look at the example |
@benhalverson what is the status of this? Would you mind updating to |
lib/internal/errors.js
Outdated
@@ -270,6 +270,11 @@ E('ERR_SOCKET_CLOSED', 'Socket is closed'); | |||
E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running'); | |||
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed'); | |||
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed'); | |||
E('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF'); | |||
// E('ERR_STREAM_READ_NOT_IMPLEMENTED', '_read() is not implemented'); |
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.
why is this commented out?
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 was testing and forgot to uncomment
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 could use some assistance on this test...
current test
function pushError() {
assert.throws(function() {
r.push(Buffer.allocUnsafe(1));
}, /^ERR_STREAM_PUSH_AFTER_EOF/);
}
What I have tried so far:
function pushError() {
common.expectsError({
code: 'ERR_STREAM_PUSH_AFTER_EOF',
message: 'stream.push() after EOF'
});
}
This gives the following error.
Path: parallel/test-stream-unshift-read-race
ok
events.js:182
throw er; // Unhandled 'error' event
^
Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:243:30)
at Readable.push (_stream_readable.js:211:10)
at pushError (/Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js:77:9)
at Timeout._onTimeout (/Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js:64:25)
at ontimeout (timers.js:471:11)
at tryOnTimeout (timers.js:305:5)
at Timer.listOnTimeout (timers.js:265:5)
Without r.push(Buffer.allocUnsafe(1));
I get this error.
Path: parallel/test-stream-unshift-read-race
Mismatched <anonymous> function calls. Expected exactly 1, actual 0.
at Object.exports.mustCall (/Users/benhalverson/projects/node/test/common/index.js:482:10)
at Object.expectsError (/Users/benhalverson/projects/node/test/common/index.js:707:27)
at pushError (/Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js:78:14)
at Timeout._onTimeout (/Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js:64:25)
at ontimeout (timers.js:471:11)
at tryOnTimeout (timers.js:305:5)
at Timer.listOnTimeout (timers.js:265:5)
0: asdfasdfas
1: 1234dfasdf
2: 1234asdfas
3: 1234dfasdf
4: 1234asdfas
5: 1234dfasdf
6: 1234asdfas
7: 1234dfasdf
8: 1234asdfas
9: 1234dfasdf
a: 1234asdfas
b: 1234dfasdf
c: 1234asdfas
d: 1234dfasdf
e: 1234asdfas
f: 1234dfasdf
g: 1234asdfa
h: 1234
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 figured it out @mcollina. Reading the docs helped 👍 https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md
Something went wrong with your latest git operations. Can you please rebase? |
I would recommend that you take the changes you have done, start with a fresh branch, and do a force push here. |
I was thinking the same... I did the rebase got a bunch of conflicts and it ended up like this after I fixed the conflicts ¯_(ツ)_/¯ |
@benhalverson against what branch did you rebase? I am not sure how you set up your clone but I guess you should rebase like |
@BridgeAR I used my local version of node and rebased against upstream/master. |
@@ -5,4 +5,4 @@ const assert = require('assert'); | |||
|
|||
const readable = new stream.Readable(); | |||
|
|||
assert.throws(() => readable.read(), /not implemented/); | |||
assert.throws(() => readable.read(), /ERR_STREAM_READ_NOT_IMPLEMENTED/); |
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.
can you use common.expectsError
here as well?
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've updated this test
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 with a nit
lib/_stream_readable.js
Outdated
@@ -1043,7 +1045,7 @@ function endReadable(stream) { | |||
// If we get here before consuming all the bytes, then that is a | |||
// bug in node. Should never happen. | |||
if (state.length > 0) | |||
throw new Error('"endReadable()" called on non-empty stream'); | |||
throw new errors.Error('ERR_STREAM_READABLE_CALLED_ON_NONEMPTY'); |
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 should be ERR_STREAM_ENDREADABLE_CALLED_ON_NONEMPTY
.
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've updated this line
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 the error code to be changed, I'm moving my feedback to "request changes" instead of approved.
Oops 😂 |
@mcollina is there anything else I need to change? |
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
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
Looks like the CI job had conflicts even though the PR says it can be merge automatically. @benhalverson could you squash the commits down 1 one (I'm thinking maybe something that is added/them removed is the source of the conflicts) and then we can run the CI again. |
I have went ahead and squashed the commits in this PR. CI: https://ci.nodejs.org/job/node-test-pull-request/11041/ |
Oh, this feature is nice: https://ci.nodejs.org/job/node-test-linter/13033/console
@benhalverson 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. |
@joyeecheung that error code is not present in readable. I think this should land asap before 9. |
@mcollina Oh, I think I posted in the wrong thread, this error is from the querystring error migration PR. The errors for this one is
Also there are some incorrect use of |
I have fixed the errors and added documentation. New CI: https://ci.nodejs.org/job/node-test-pull-request/11044/ @jasnell @BridgeAR @mcollina @addaleax @gireeshpunathil @mhdawson PTAL |
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.
FWIW
(CI failures are unrelated build issues.) |
Landed as 88fb359 |
PR-URL: #15042 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: nodejs/node#15042 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: nodejs/node#15042 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Ref #11273
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
_stream_readable