--watch prints messages to stdout, but should print to stderr
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 122k
- Forks
- 37.3k
- Merge moyen
- 4 j 2 h
- PR mergées (30 j)
- 283
Description
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?
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans lib/internal/main/watch_mode.js, en particulier au niveau de l’utilisation de stdout près de la ligne liée, et exécutez la reproduction signalée node --watch index.mjs avec stderr redirigé. C’est terminé lorsque les messages du mode watch tels que "Restarting 'index.mjs'" sont envoyés vers stderr, afin qu’ils soient supprimés par 2>/dev/null et n’interfèrent pas avec la stdout du programme.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- cli
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 76/100