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

Migrate _stream_readable errors to internal/errors #15042

Closed
wants to merge 4 commits into from
Closed

Migrate _stream_readable errors to internal/errors #15042

wants to merge 4 commits into from

Conversation

benhalverson
Copy link
Member

@benhalverson benhalverson commented Aug 26, 2017

Ref #11273

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

_stream_readable

@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. stream Issues and PRs related to the stream subsystem. labels Aug 26, 2017
@benhalverson
Copy link
Member Author

@jasnell I wasn't able to get the tests to pass...

Path: parallel/test-stream-unshift-read-race
ok
assert.js:621
      throw actual;
      ^

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at readableAddChunk (_stream_readable.js:244:30)
    at Readable.push (_stream_readable.js:212:10)
    at /Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js:72:7
    at tryBlock (assert.js:591:5)
    at innerThrows (assert.js:610:18)
    at Function.throws (assert.js:637:3)
    at pushError (/Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js:71:10)
    at Timeout._onTimeout (/Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js:64:25)
    at ontimeout (timers.js:469:11)
    at tryOnTimeout (timers.js:304:5)
Command: out/Release/node /Users/benhalverson/projects/node/test/parallel/test-stream-unshift-read-race.js
[02:20|% 100|+ 1799|-   1]: Done
make: *** [test] Error 1

my attempt...

function pushError() {
  assert.throws(function() {
    r.push(Buffer.allocUnsafe(1));
  }, /^ERR_STREAM_PUSH_AFTER_EOF$/);
}


const w = stream.Writable();
const written = [];
w._write = function(chunk, encoding, cb) {
  written.push(chunk.toString());
  cb();
};

r.on('end', common.mustCall(function() {
  assert.throws(function() {
    r.unshift(Buffer.allocUnsafe(1));
  }, /^ERR_STREAM_UNSHIFT_AFTER_END_EVENT$/);
  w.end();
}));

@jasnell
Copy link
Member

jasnell commented Aug 26, 2017

Ping @nodejs/streams @mcollina

@mcollina
Copy link
Member

As stated elsewhere, I'm very 👎 on this change until we have a clear strategy on how to keep the same behavior on readable-stream (it needs to support old browsers were inheriting from Error does not work as expected).

@benhalverson
Copy link
Member Author

@mcollina thanks for the feedback.

@refack refack added the blocked PRs that are blocked by other issues or PRs. label Aug 26, 2017
@refack
Copy link
Contributor

refack commented Aug 26, 2017

Hello @benhalverson and welcome. Thank you for the contribution 🥇
AFAICT on the face of it this PR is good, it's just a matter of timing and coordination with the readable-stream package.

I've marked it as blocked until a compatibility strategy is finalized.

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

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

@@ -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'));
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_UNDERSCORE_READ_NOT_IMPLEMENTED/ERR_STREAM_READ_NOT_IMPLEMENTED

@@ -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');
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_END_READABLE_CALLED_ON_NONEMPTY_STREAM/ERR_STREAM_READABLE_CALLED_ON_NONEMPTY

@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

To explain @refack's comments a bit more. The streams module in core is kept in sync with the standalone readable-streams module. Because of that, any changes to the streams code must be kept in sync with that module. Because the internal/errors bit is very specific to Node.js core, we have not started migrating the streams code over to use it.

@mcollina mcollina removed the blocked PRs that are blocked by other issues or PRs. label Sep 12, 2017
@mcollina
Copy link
Member

mcollina commented Sep 12, 2017

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.

Ref: nodejs/readable-stream#309 (comment)

@mcollina
Copy link
Member

@benhalverson
Copy link
Member Author

Thanks @mcollina I'll take a look at the example

@mcollina
Copy link
Member

@benhalverson what is the status of this? Would you mind updating to common.expectsError({ code: 'CODE' })?

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

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?

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@mcollina
Copy link
Member

Something went wrong with your latest git operations. Can you please rebase?

@mcollina
Copy link
Member

I would recommend that you take the changes you have done, start with a fresh branch, and do a force push here.

@benhalverson
Copy link
Member Author

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 ¯_(ツ)_/¯

@BridgeAR
Copy link
Member

@benhalverson against what branch did you rebase? I am not sure how you set up your clone but I guess you should rebase like git rebase -i upstream/master.

@benhalverson
Copy link
Member Author

@BridgeAR I used my local version of node and rebased against upstream/master.
After I committed my local changes I typed git rebase upstream master git applied all the upstream changes then added mine and also showed a bunch of conflicts on files I didn't touch. I used my IDE (webstorm) to resolve the conflicts by accepting their changes and then pushed to my local branch.

@@ -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/);
Copy link
Member

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?

Copy link
Member Author

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

@mcollina
Copy link
Member

Copy link
Member

@mcollina mcollina left a 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

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

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.

Copy link
Member Author

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

Copy link
Member

@mcollina mcollina left a 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.

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 25, 2017
@benhalverson
Copy link
Member Author

Oops 😂

@benhalverson
Copy link
Member Author

@mcollina is there anything else I need to change?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina mcollina requested a review from a team October 6, 2017 21:08
@addaleax
Copy link
Member

addaleax commented Oct 7, 2017

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

@mhdawson
Copy link
Member

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.

@joyeecheung
Copy link
Member

I have went ahead and squashed the commits in this PR. CI: https://ci.nodejs.org/job/node-test-pull-request/11041/

@joyeecheung
Copy link
Member

Oh, this feature is nice:

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

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

@mcollina
Copy link
Member

@joyeecheung that error code is not present in readable. I think this should land asap before 9.

@joyeecheung
Copy link
Member

@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

not ok 11 - /usr/home/iojs/build/workspace/node-test-linter/lib/internal/errors.js
  ---
  message: >-
    "ERR_STREAM_ENDREADABLE_CALLED_ON_NONEMPTY" is not documented in
    doc/api/errors.md
  severity: error
  data:
    line: 326
    column: 1
    ruleId: documented-errors
  messages:
    - message: >-
        doc/api/errors.md does not have an anchor for
        "ERR_STREAM_ENDREADABLE_CALLED_ON_NONEMPTY"
      severity: error
      data:
        line: 326
        column: 1
        ruleId: documented-errors
    - message: '"ERR_STREAM_PUSH_AFTER_EOF" is not documented in doc/api/errors.md'
      severity: error
      data:
        line: 328
        column: 1
        ruleId: documented-errors
    - message: doc/api/errors.md does not have an anchor for "ERR_STREAM_PUSH_AFTER_EOF"
      severity: error
      data:
        line: 328
        column: 1
        ruleId: documented-errors
    - message: '"ERR_STREAM_READ_NOT_IMPLEMENTED" is not documented in doc/api/errors.md'
      severity: error
      data:
        line: 329
        column: 1
        ruleId: documented-errors
    - message: >-
        doc/api/errors.md does not have an anchor for
        "ERR_STREAM_READ_NOT_IMPLEMENTED"
      severity: error
      data:
        line: 329
        column: 1
        ruleId: documented-errors
    - message: >-
        "ERR_STREAM_UNSHIFT_AFTER_END_EVENT" is not documented in
        doc/api/errors.md
      severity: error
      data:
        line: 330
        column: 1
        ruleId: documented-errors
    - message: >-
        doc/api/errors.md does not have an anchor for
        "ERR_STREAM_UNSHIFT_AFTER_END_EVENT"
      severity: error
      data:
        line: 330
        column: 1
        ruleId: documented-errors
  ...

Also there are some incorrect use of common.expectsError, I will fix those as well.

@joyeecheung
Copy link
Member

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

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.

FWIW

@Trott
Copy link
Member

Trott commented Oct 28, 2017

(CI failures are unrelated build issues.)

@mcollina
Copy link
Member

Landed as 88fb359

@mcollina mcollina closed this Oct 29, 2017
mcollina pushed a commit that referenced this pull request Oct 29, 2017
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>
Qard pushed a commit to ayojs/ayo that referenced this pull request Nov 2, 2017
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>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
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>
@benhalverson benhalverson deleted the stream_readable_error branch December 15, 2017 04:57
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. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.