-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
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 87.95% 87.96%
=======================================
Files 656 656
Lines 188310 188315 +5
Branches 35963 35973 +10
=======================================
+ Hits 165630 165645 +15
+ Misses 15854 15848 -6
+ Partials 6826 6822 -4
|
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
5c1a3e6
to
26b3e41
Compare
Had some unrelated coverage failure on Windows, rebased and rerun everything |
This error is related to the VS v17.12 which was released a week ago and has a compiler change making Node.js compilation impossible. I've already opened an issue to track this in build: nodejs/build#3963. I've also reported this to Microsoft via the developer community issue. |
26b3e41
to
b1c5b00
Compare
CI is green again, can I get another approval or can someone take another look (since I need to rebase to pass the GHA) 🙏 |
This PR is technically ready to land, would you mind taking another quick look on CITGM @mcollina Also need another approval since this PR needed a rebase |
Any news about this PR? We couldn’t found a workaround. And I couldn’t confirm if this PR fixes the issue. |
Hi @mshima I have a few questions here:
|
@jakecastelli thanks for your attention. In my tests, node 22.4.0 works as expected. Creating a minimal reproduction to match our use case is quite difficult, but seems likely this issue.
replace:
with (to make prettier fail):
Generate with offending file in an empty folder:
|
Thanks for providing some more info, I haven't run the script yet to install the pkg, could you confirm if the package name is correct? I searched on npm and found this https://www.npmjs.com/package/jhipster?activeTab=readme and is probably not the one I suppose to install |
@jakecastelli sorry it’s generator-jhipster |
This is the error I've got, do you mind explaining a bit more on why you think this is related to the pipeline? And how do I test with node error
|
That's the expected error.
Looks related to pipeline transforms like: Duplex.from(async function* (files: AsyncGenerator<MemFsEditorFile>) {
for await (const file of files) {
if (isFilePending(file)) {
yield file;
}
}
}),
I use
It's not a single place, yeoman/generator#1577, SBoudrias/mem-fs-editor#282, SBoudrias/mem-fs#40. |
Hi @aduh95 I see you've helped with the CITGM result here - #55270 (comment) 🙏 I have to admit, I'm not entirely sure how to interpret the results. Is there any documentation that explains how to understand the CITGM results? For this PR, are there any user-land packages I should examine more closely? |
Landed in fd8de67 |
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: