--watch prints messages to stdout, but should print to stderr

Offen Anfängerfreundlich
#56,478 4 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Ruhig
Tech-Stack
javascript
Bereich
cli

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.

Beschreibung

watch-mode
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?

Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.4k
Ø Merge
4 T. 3 Std.
Gemergte PRs (30 T.)
273

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus nodejs/node

Alle Issues in nodejs/node

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.