`fsPromise.writeFile` should catch stream's error and reject the promise.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.3k
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 283
Beschreibung
Version
22.16.0
Platform
All
Subsystem
No response
What steps will reproduce the bug?
Following code fails with an application crash.
import fsp from "node:fs/promises";
import { createReadStream } from "node:fs";
try {
const s1 = createReadStream("not-existent");
await fsp.writeFile("new-file.txt", s1);
} catch (error) {
console.log(`Sorry file copy failed`);
}
Instead it should just say that an error has occurred and reject the promise.
How often does it reproduce? Is there a required condition?
Everytime
What is the expected behavior? Why is that the expected behavior?
The application should not crash and an error should be thrown.
What do you see instead?
Application Crashes.
Reproduction Repository
ackava/node-write-file-promise-fail
This repo contains docker container source code to reproduce error in container. On windows machine, delay causes app to crash but in container, slight delay of 1 ms causes crash.
Workaround
So far following code works correctly with slight time differences, and does not crash the app, promise is rejected correctly.
const writable = createWriteStream(outputFilePath);
return pipeline(inputStream, writable, { end: true });
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den in der Reproduktion gezeigten Einstiegspunkten fsPromise.writeFile und createReadStream und vergleiche anschließend deren Fehlerbehandlung mit dem pipeline-Workaround. Verwende das verlinkte Reproduktions-Repository, um den Absturz zu reproduzieren und zu überprüfen, dass ein fehlendes Eingabefile das Promise ablehnt, anstatt die Anwendung zum Absturz zu bringen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, nodejs
- Bereich
- operating-systems
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100