-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: catch and forward error from dest.write #55270
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
I don't think it should be supported. It is most likely a programmer error. |
76823e6
to
6dfdf7e
Compare
I agree, but I am afraid this would break many user land packages. |
We could mark it as semver-major and run CITGM. I think it should be fixed in the "broken" packages and I don't think there are many of them. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55270 +/- ##
==========================================
- Coverage 88.42% 87.92% -0.50%
==========================================
Files 654 654
Lines 187852 187857 +5
Branches 36134 35832 -302
==========================================
- Hits 166102 165170 -932
- Misses 14989 15877 +888
- Partials 6761 6810 +49
|
I've been thinking about it, and I think we should more carefully consider whether we should throw directly in The reasons being:
To wrap up, what I am trying to say is that we may wanna consider this breaking change more carefully as all the cc. @nodejs/streams |
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 will likely break a lot of modules.
Many people (including myself) use object mode streams with strings or buffers. Even Node.js Core implies that, as we assumed this when we flipped Readable.from()
to always be in object mode: Readable.from(['a', 'b']).pipe(fs.createWriteStream())
@mcollina I think you misunderstand this PR. It basically fixes an uncatchable error. Doesn't break anything as far as I can tell. |
Though I do think this PR is a little over engineered. It's enough to catch the error and forward it "as is" to destroy. |
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 totally misunderstood this. I've left a few comments.
Thank you for the review! 🙏 I appreciate the feedback and am happy to remove this error. As @ronag pointed out, it seems like I may have over-engineered it. My initial intention was to help developers understand the error better, but looking back, it appears I might've complicated things more than I've fixed. Another point for discussion is whether we should catch the error and call destroy on the |
I disagree with @lpinca on this one and would prefer a catchable error. The exception guarantee is understandable and it's possible to isolate the error from other working parts of a service, i.e. better to have a http server return 500 on a broken path than stop responding on all paths. |
The error is already understandable (your suggestion is to call I would also argue that if we want this behavior we should make |
@ronag this change of behavior would be semver-major anyway. |
I'm still unsure about whether we should catch the error or proceed with a hard crash. Is there a similar example in Node.js core that we could use for comparison? On the other hand, does those lines make sense? diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js
index ac14b202b6..5225aa13f4 100644
--- a/lib/internal/streams/writable.js
+++ b/lib/internal/streams/writable.js
@@ -477,8 +477,9 @@ function _write(stream, chunk, encoding, cb) {
chunk = Stream._uint8ArrayToBuffer(chunk);
encoding = 'buffer';
} else {
- throw new ERR_INVALID_ARG_TYPE(
- 'chunk', ['string', 'Buffer', 'TypedArray', 'DataView'], chunk);
+ stream.destroy(new ERR_INVALID_ARG_TYPE(
+ 'chunk', ['string', 'Buffer', 'TypedArray', 'DataView'], chunk));
+ return
}
} or I should move what I've done in the catch block into |
I think your PR was fine other than there is no need to convert it into another error. |
c01a0b9
to
52d26c2
Compare
52d26c2
to
de9f68a
Compare
de9f68a
to
6e3329b
Compare
Would be great to have some reviews, no hard feeling if folks would like to block it @nodejs/streams |
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 green CITGM and semver-major
This comment was marked as outdated.
This comment was marked as outdated.
Do you mind taking another quick look? @mcollina 🙏 |
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
I have a bad feeling this would be massively breaking.
I don't see how. Is it just a feeling or do you have some ideas in regards to how? |
Bad feeling, but I don't see how. Let's do another CITGM run: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/3507/ main: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/3508/ |
6e3329b
to
81d5084
Compare
81d5084
to
5c1a3e6
Compare
Fixes: #54945
Wanted to give a quick mention why checking object modes at the start of the pipe function wouldn't work (even though I liked the idea). Because if the chunk from the source stream is not object while source stream is in object mode and destination stream is not in object mode, it should still work.
Consider the following example: