fs: handle early writeFile stream errors#63472
Open
cookesan wants to merge 3 commits into
Open
Conversation
Attach a temporary error listener to readable stream inputs before opening the destination file. This lets writeFile() reject with the stream error instead of allowing an early source error to become an uncaught exception. Remove the listener when the write finishes or when opening the destination fails. Signed-off-by: cookesan <6601329+cookesan@users.noreply.github.com>
a3d19d5 to
c1d1472
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63472 +/- ##
==========================================
- Coverage 91.67% 90.33% -1.34%
==========================================
Files 361 730 +369
Lines 156408 234262 +77854
Branches 24050 43945 +19895
==========================================
+ Hits 143384 211623 +68239
- Misses 12751 14379 +1628
- Partials 273 8260 +7987
🚀 New features to boost your workflow:
|
Signed-off-by: cookesan <6601329+cookesan@users.noreply.github.com>
Keep the temporary writeFile error listener through the pending next-tick error emission when a stream is already errored at entry. This lets writeFile reject from the stored stream error without letting the stream emit an unhandled error, and still removes the listener after the pending emission. Signed-off-by: cookesan <6601329+cookesan@users.noreply.github.com>
Contributor
Author
|
Pushed a follow-up for the failing writeFile stream cases. The already-errored stream path now keeps the temporary Local validation:
|
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
fs.promises.writeFile()stream path could miss a readableerror emitted before the destination file opened. The returned promise
could reject while the source stream error also surfaced as an uncaught
exception.
This attaches a temporary error listener for readable stream inputs
before opening the destination, checks recorded stream errors before and
during async iteration, and removes the listener when the write finishes
or when opening the destination fails.
FileHandle.writeFile()uses thesame helper.
Tests cover early readable errors for path and
FileHandlewrites, pluslistener cleanup when opening the destination fails.
Tests:
Fixes: #58742