Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lydell opened this issue Jan 5, 2025 · 0 comments
Open

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

lydell opened this issue Jan 5, 2025 · 0 comments

Comments

@lydell
Copy link

lydell commented Jan 5, 2025

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:

process.stdout.write(`${green}Restarting ${kCommandStr}${white}\n`);

Is there a reason for this? Should it be changed to stderr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant