-
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
stream: improve multiple callback error message #12520
Conversation
lib/_stream_transform.js
Outdated
function emitMultipleCallsError() { | ||
this.emit('error', new Error('write callback called multiple 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'm good with this, but it may make sense at some point to make this a utility in internal/util
given that there may be several places where we'd want to avoid calling a callback more than once
lib/_stream_transform.js
Outdated
@@ -92,7 +96,7 @@ function afterTransform(stream, er, data) { | |||
return stream.emit('error', new Error('no writecb in Transform class')); | |||
|
|||
ts.writechunk = null; | |||
ts.writecb = null; | |||
ts.writecb = emitMultipleCallsError.bind(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.
Note. If this PR gets accepted, this bind()
could be moved to, for example, the stream constructor, and hidden with a symbol. That would avoid rebinding every time.
lib/_stream_transform.js
Outdated
@@ -92,7 +96,7 @@ function afterTransform(stream, er, data) { | |||
return stream.emit('error', new Error('no writecb in Transform class')); |
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.
Isn't this line useless if you assign non-null value to ts.writecb
below?
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 left this alone to be safe. However, I haven't found any path to this code that doesn't involve calling the callback twice, or using internal APIs. If that's the case, the fix can be as simple as changing the error message on this line. I'll take a look in the morning.
@mscdex why semver-major? |
@mcollina Change in error message? |
@mscdex great, I think we can release it with a minor in I'm fine with a minor here as well, I do not think anyone is relying on this error, the whole stream is broken if the error happens anyway. |
@mcollina I think we still have the policy that any error message changes are automatically semver-major, so I don't see that changing here. Perhaps later on down the road after the new centralized error information has been around for awhile we can revisit that policy. |
yeah especially considering it wasn't a documented error message, we can get away with minor in readable-streams |
Updated to only change the error message. CI: https://ci.nodejs.org/job/node-test-pull-request/8175/ |
lib/_stream_transform.js
Outdated
@@ -89,7 +89,8 @@ function afterTransform(stream, er, data) { | |||
var cb = ts.writecb; | |||
|
|||
if (!cb) |
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 we add braces here since the body is now multi-line?
Added curly braces, and CI was green. |
@jasnell @abouthiroppy you may want to re-review |
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. We still need to get the errors in here converted over to use internal/errors
tho... so that's something to keep in mind for later
When a transform stream's callback is called more than once, an error is emitted with a somewhat confusing message. This commit hopes to improve the quality of the error message. Fixes: nodejs#12513 PR-URL: nodejs#12520 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
this technically landed after the semver major cutoff @nodejs/ctc does anyone have an issue with this landing in the 8.0.0 release? |
When a transform stream's callback is called more than once, an error is emitted with a somewhat confusing message. This commit hopes to improve the quality of the error message. Fixes: #12513 PR-URL: #12520 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
When a transform stream's callback is called more than once, an error is emitted with a somewhat confusing message. This commit hopes to improve the quality of the error message. Fixes: #12513 PR-URL: #12520 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
When a transform stream's callback is called more than once, an error is emitted with a somewhat confusing message. This commit hopes to improve the quality of the error message.
Fixes: #12513
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
stream