--watch prints messages to stdout, but should print to stderr
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
v22.12.0
Platform
macOS (but reading the source code of Node.js the issue should be present on any platform)
Subsystem
node/lib/internal/main/watch_mode.js
What steps will reproduce the bug?
echo 'process.stdin.resume()' >index.mjs
node --watch index.mjs 2>/dev/null
In another terminal:
touch index.mjs
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior? Why is that the expected behavior?
Nothing is printed, since I redirect stderr to /dev/null.
What do you see instead?
Restarting 'index.mjs' is printed (to stdout).
Additional information
How to use stdout and stderr is purely conventional, but the GNU C library says:
stdout: The standard output stream, which is used for normal output from the program.
stderr: The standard error stream, which is used for error messages and diagnostics issued by the program.
I’m making a program that reads input from stdin and writes to stdout. It is a long-lived program: Another program writes to stdin over time, and consumes output from stdout. I use --watch so I can iterate on the sub-program more easily. Unfortunately, --watch writes messages to stdout, causing the consuming program to receive output it does not expect.
I would argue that my program creates the “normal output” while the --watch messages are “diagnostics”.
Here’s one of the places where stdout is used instead of stderr: https://github.com/nodejs/node/blob/9400eae52ee10f25d63c06c52479c033e3149580/lib/internal/main/watch_mode.js#L139
Is there a reason for this? Should it be changed to stderr?
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 in lib/internal/main/watch_mode.js, insbesondere bei der stdout-Verwendung in der Nähe der verlinkten Zeile, und führe die gemeldete Reproduktion node --watch index.mjs mit umgeleitetem stderr aus. Fertig ist die Änderung, wenn Meldungen des Watch-Modus wie "Restarting 'index.mjs'" an stderr gehen, sodass sie durch 2>/dev/null unterdrückt werden und die stdout des Programms nicht beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- cli
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 76/100