nodejs / nodejs/node

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

Đang mở Phù hợp với người mới
#56,478 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

watch-mode
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong lib/internal/main/watch_mode.js, đặc biệt là chỗ sử dụng stdout gần dòng được liên kết, và chạy reproduction node --watch index.mjs đã được báo cáo với stderr được chuyển hướng. Được xem là hoàn tất khi các thông báo của watch mode như "Restarting 'index.mjs'" được gửi đến stderr để 2>/dev/null loại bỏ chúng và chúng không can thiệp vào stdout của chương trình.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
76/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.