`fsPromise.writeFile` should catch stream's error and reject the promise.
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
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 });
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dagli entry point fsPromise.writeFile e createReadStream mostrati nella riproduzione, quindi confronta la loro gestione degli errori con il workaround basato su pipeline. Usa il repository di riproduzione collegato per riprodurre il crash e verificare che la mancanza del file di input rifiuti la promise invece di causare il crash dell’applicazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, nodejs
- Ambito
- operating-systems
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100