FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

stream: make virtual methods errors consistent by lpinca · Pull Request #18813 · nodejs/node · GitHub

/ node Public

stream: make virtual methods errors consistent - #18813

Closed
lpinca wants to merge 1 commit into
nodejs:masterfrom
lpinca:uniform/virtual-methods-errors
Closed

stream: make virtual methods errors consistent#18813
lpinca wants to merge 1 commit into
nodejs:masterfrom
lpinca:uniform/virtual-methods-errors

Conversation

lpinca commented Feb 16, 2018
edited
Loading

Copy link
Copy Markdown
Member

Use the same error code and always emit the error instead of throwing it.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

errors, stream

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 Feb 16, 2018
lpinca added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 16, 2018

lpinca commented Feb 16, 2018
edited
Loading

Copy link
Copy Markdown
Member Author

lpinca added the wip Issues and PRs that are still a work in progress. label Feb 16, 2018
lpinca force-pushed the uniform/virtual-methods-errors branch 2 times, most recently from e5aa300 to 90809ef Compare February 16, 2018 12:52
lpinca removed the wip Issues and PRs that are still a work in progress. label Feb 16, 2018

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

BridgeAR added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Feb 16, 2018
BridgeAR requested a review from a team February 16, 2018 17:35

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the correct behavior for these is to emit('error'). Note that calling the callback with an error will have that result.

Comment thread lib/_stream_readable.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would leave this as this.emit('error').

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you elaborate on the reasons?

Comment thread lib/_stream_transform.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would change this as cb(new errors.Error()).

Comment thread lib/_stream_writable.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would leave this as it was.

Comment thread lib/internal/errors.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

👍!

BridgeAR removed the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Feb 16, 2018

lpinca commented Feb 16, 2018
edited
Loading

Copy link
Copy Markdown
Member Author

Note that calling the callback with an error will have that result.

Yes, I changed it because I think it doesn't make sense to emit the error, it should just crash as the method has not been implemented. If there is an 'error' listener this may go unnoticed.

Anyway happy to always emit the error instead of throwing if there is consensus.

Copy link
Copy Markdown
Member

I think throwing is not the way to go, mainly because that error is likely not to be catchable in any way.

jasnell commented Feb 16, 2018

Copy link
Copy Markdown
Member

I agree with @mcollina that these should be emit('error', ...) ... it's much more consistent with what users expect with stream implementations.

lpinca commented Feb 17, 2018

Copy link
Copy Markdown
Member Author

I think throwing is not the way to go, mainly because that error is likely not to be catchable in any way.

Isn't this the point of the error? We throw for invalid arguments or options, in my opinion this is the same kind of error (invalid implementation).

I guess this

throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_implicitHeader()');
should also be emitted if we agree that these errors should be emitted.

Copy link
Copy Markdown
Member

The reason why these needs to be emitted is because they could be called asynchronously. In such cases it would be hard to track to which stream they belong.

lpinca commented Feb 17, 2018
edited
Loading

Copy link
Copy Markdown
Member Author

I still fail to understand.

  1. If there is no 'error' listener the error will be thrown and the stack trace will be exactly the same as if the error was thrown in the first place.
  2. If there is at least an 'error' listener, the developer has to stop the process, add a proper implementation and restart it, and again the stack trace will be exactly the same as if the error was thrown. How can this help determine which stream generated the error?

That said, I will change this PR to always emit if this is the right thing to do.

Pinging @nodejs/collaborators.

lpinca force-pushed the uniform/virtual-methods-errors branch from 90809ef to e19a9d1 Compare February 19, 2018 11:03

lpinca commented Feb 19, 2018

Copy link
Copy Markdown
Member Author

No one commented and there are 2 TSC members that prefer to emit, so I've updated accordingly.

lpinca commented Feb 19, 2018

Copy link
Copy Markdown
Member Author

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Copy link
Copy Markdown
Member

This needs a rebase

lpinca force-pushed the uniform/virtual-methods-errors branch from e19a9d1 to 54c0ab1 Compare February 23, 2018 13:18

lpinca commented Feb 23, 2018

Copy link
Copy Markdown
Member Author

BridgeAR commented Mar 2, 2018

Copy link
Copy Markdown
Member

@mcollina @jasnell e.g. all our fs errors throw sync instead of returning the error in the callback. That is also true for any other part of the code. So I am still not convinced about using emit here. All of that code could be used async. The only way I can imagine how these functions could be called is by faulty user code. And for me that is the same as the fs case.

mcollina commented Mar 2, 2018

Copy link
Copy Markdown
Member

@BridgeAR I would agree if those function were called sync all the time. In non-trivial cases, those methods are called async.

lpinca commented Mar 2, 2018

Copy link
Copy Markdown
Member Author

@mcollina it doesn't matter imho, what's the difference, any method or function that throws synchronously can be called async.

mcollina commented Mar 2, 2018

Copy link
Copy Markdown
Member

All Node APIs can be called async from user code. These are called async from Node.js code.

Copy link
Copy Markdown
Member

I think when to throw such errors depends on the nature of those errors: can they be expected from a user, or are they just bugs/incorrect usage of APIs. In the first case it make sense to throw asynchronously because we cannot know the result of an async operation synchronously anyway. In the second case it makes sense to throw synchronously because those errors are more like assertions in nature. The async operations cannot even be initiated so there is not really much point to delay the notification.

Also the user cannot really handle those errors (type checking, streams not implemented, etc) in their code anyway. The only sane way to handle those errors is probably just throw it again. If they try to handle a ERR_INVALID_* or ERR_METHOD_NOT_IMPLEMENTED they are probably just going to leave their program in a really bad state.

lpinca added this to the 10.0.0 milestone Mar 11, 2018
Use the same error code and always emit the error instead of
throwing it.
lpinca force-pushed the uniform/virtual-methods-errors branch from 54c0ab1 to f8bd8ec Compare March 11, 2018 09:55

lpinca commented Mar 11, 2018
edited
Loading

Copy link
Copy Markdown
Member Author

I will land this tomorrow, got bored of rebasing :)
CI: https://ci.nodejs.org/job/node-test-pull-request/13619/
CI: https://ci.nodejs.org/job/node-test-pull-request/13642/

lpinca added a commit that referenced this pull request Mar 12, 2018
Use the same error code and always emit the error instead of
throwing it.

PR-URL: #18813
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaë Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

lpinca commented Mar 12, 2018

Copy link
Copy Markdown
Member Author

Landed in c979488.

lpinca closed this Mar 12, 2018
lpinca deleted the uniform/virtual-methods-errors branch March 12, 2018 13:30
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Use the same error code and always emit the error instead of
throwing it.

PR-URL: nodejs#18813
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaë Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
ChALkeR added a commit to ChALkeR/io.js that referenced this pull request Aug 6, 2018
This removes two unused error codes:
 * ERR_STREAM_READ_NOT_IMPLEMENTED, removed in c979488 (PR nodejs#18813).
 * ERR_VALUE_OUT_OF_RANGE, removed in d022cb1 (PR nodejs#17648).

PR-URL: nodejs#21491
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
targos pushed a commit that referenced this pull request Aug 6, 2018
This removes two unused error codes:
 * ERR_STREAM_READ_NOT_IMPLEMENTED, removed in c979488 (PR #18813).
 * ERR_VALUE_OUT_OF_RANGE, removed in d022cb1 (PR #17648).

PR-URL: #21491
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

7 participants


Back | FazBrowse Home | New Git URL