nodejs / nodejs/node

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

未关闭 适合新手
#56,478 4 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

watch-mode
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 lib/internal/main/watch_mode.js 开始,尤其关注链接行附近对 stdout 的使用,并在重定向 stderr 的情况下运行报告中的 node --watch index.mjs 复现。完成的标准是,"Restarting 'index.mjs'" 等 watch 模式消息会发送到 stderr,从而被 2>/dev/null 抑制,不会干扰程序的 stdout。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
cli
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
冷清
描述清晰度
描述清楚
新手友好度
76/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。