Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upstream: make virtual methods errors consistent #18813
Conversation
nodejs-github-bot
added
errors
stream
labels
Feb 16, 2018
lpinca
added
the
semver-major
label
Feb 16, 2018
This comment has been minimized.
This comment has been minimized.
lpinca
added
the
work in progress (WIP)
label
Feb 16, 2018
lpinca
force-pushed the
lpinca:uniform/virtual-methods-errors
branch
2 times, most recently
from
e5aa300
to
90809ef
Feb 16, 2018
lpinca
removed
the
work in progress (WIP)
label
Feb 16, 2018
jasnell
approved these changes
Feb 16, 2018
BridgeAR
added
the
author ready
label
Feb 16, 2018
BridgeAR
requested a review
from nodejs/tsc
Feb 16, 2018
targos
approved these changes
Feb 16, 2018
mcollina
requested changes
Feb 16, 2018
|
I think the correct behavior for these is to |
| @@ -561,7 +561,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 errors.Error('ERR_STREAM_READ_NOT_IMPLEMENTED')); | |||
| throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_read()'); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -157,7 +157,7 @@ Transform.prototype.push = function(chunk, encoding) { | |||
| // an error, then that'll put the hurt on the whole operation. If you | |||
| // never call cb(), then you'll never get another chunk. | |||
| Transform.prototype._transform = function(chunk, encoding, cb) { | |||
| throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_transform'); | |||
| throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_transform()'); | |||
This comment has been minimized.
This comment has been minimized.
| @@ -541,7 +541,7 @@ function clearBuffer(stream, state) { | |||
| } | |||
|
|
|||
| Writable.prototype._write = function(chunk, encoding, cb) { | |||
| cb(new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_write')); | |||
| throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_write()'); | |||
This comment has been minimized.
This comment has been minimized.
| @@ -761,7 +761,6 @@ E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed'); | |||
| E('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable'); | |||
| E('ERR_STREAM_NULL_VALUES', 'May not write null values to stream'); | |||
| E('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF'); | |||
| E('ERR_STREAM_READ_NOT_IMPLEMENTED', '_read() is not implemented'); | |||
This comment has been minimized.
This comment has been minimized.
BridgeAR
removed
the
author ready
label
Feb 16, 2018
This comment has been minimized.
This comment has been minimized.
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 Anyway happy to always emit the error instead of throwing if there is consensus. |
This comment has been minimized.
This comment has been minimized.
|
I think throwing is not the way to go, mainly because that error is likely not to be catchable in any way. |
This comment has been minimized.
This comment has been minimized.
|
I agree with @mcollina that these should be |
This comment has been minimized.
This comment has been minimized.
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 Line 608 in 6c9774f |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
I still fail to understand.
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
lpinca:uniform/virtual-methods-errors
branch
from
90809ef
to
e19a9d1
Feb 19, 2018
This comment has been minimized.
This comment has been minimized.
|
No one commented and there are 2 TSC members that prefer to emit, so I've updated accordingly. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This needs a rebase |
lpinca
force-pushed the
lpinca:uniform/virtual-methods-errors
branch
from
e19a9d1
to
54c0ab1
Feb 23, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@mcollina @jasnell e.g. all our |
This comment has been minimized.
This comment has been minimized.
|
@BridgeAR I would agree if those function were called sync all the time. In non-trivial cases, those methods are called async. |
This comment has been minimized.
This comment has been minimized.
|
@mcollina it doesn't matter imho, what's the difference, any method or function that throws synchronously can be called async. |
This comment has been minimized.
This comment has been minimized.
|
All Node APIs can be called async from user code. These are called async from Node.js code. |
This comment has been minimized.
This comment has been minimized.
|
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 |
lpinca
added this to the 10.0.0 milestone
Mar 11, 2018
lpinca
force-pushed the
lpinca:uniform/virtual-methods-errors
branch
from
54c0ab1
to
f8bd8ec
Mar 11, 2018
This comment has been minimized.
This comment has been minimized.
|
I will land this tomorrow, got bored of rebasing :) |
lpinca
added a commit
that referenced
this pull request
Mar 12, 2018
This comment has been minimized.
This comment has been minimized.
|
Landed in c979488. |
lpinca commentedFeb 16, 2018
•
edited
Use the same error code and always emit the error instead of throwing it.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
errors, stream