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

fix: change stderr to stdout #70

Closed
wants to merge 3 commits into from

Conversation

SocketSomeone
Copy link

No description provided.

Copy link

changeset-bot bot commented Nov 16, 2024

🦋 Changeset detected

Latest commit: 7cb0bf7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@swc/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Nov 16, 2024

CLA assistant check
All committers have signed the CLA.

@kdy1 kdy1 requested a review from magic-akari November 16, 2024 12:29
@kdy1
Copy link
Member

kdy1 commented Nov 16, 2024

Can you describe the reason?

Copy link
Member

@magic-akari magic-akari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of stderr for outputting information is intentional and by design.
Could you explain why you wish to switch to stdout?

@SocketSomeone
Copy link
Author

SocketSomeone commented Nov 16, 2024

Can you describe the reason?

The use of stderr for outputting information is intentional and by design. Could you explain why you wish to switch to stdout?

It seems that the current version of library is using the wrong stream for its messages. In our company, we rely on reading logs from stderr to detect issues and stop the build when something goes wrong. However, it feels odd to encounter "successful errors" in the error stream. shrug

@SocketSomeone
Copy link
Author

  • stdout (Standard Output): Used for regular program output, particularly results or information that is the intended product of the program's execution.

  • stderr (Standard Error): Reserved for diagnostic messages, errors, warnings, or any information unrelated to the normal output.

Messages like "Successfully compiled ${filename} with swc" looks as information of program execution.

@magic-akari
Copy link
Member

It seems that the current version of library is using the wrong stream for its messages. In our company, we rely on reading logs from stderr to detect issues and stop the build when something goes wrong. However, it feels odd to encounter "successful errors" in the error stream. shrug

I recommend using exit code detection instead of relying on stderr to determine errors. This is because stderr output could be tips, warnings, or any other information.

  • stdout (Standard Output): Used for regular program output, particularly results or information that is the intended product of the program's execution.
  • stderr (Standard Error): Reserved for diagnostic messages, errors, warnings, or any information unrelated to the normal output.

Messages like "Successfully compiled ${filename} with swc" looks as information of program execution.

What you cited is correct; for the SWC CLI, stdout should only be the compilation output.
If the output is a file, stdout should be empty.

The "Successfully compiled" message, however, is a notification unrelated to the normal output and is expected to be emitted to stderr.

@magic-akari
Copy link
Member

magic-akari commented Nov 16, 2024

Return zero exit code on success, non-zero on failure. Exit codes are how scripts determine whether a program succeeded or failed, so you should report this correctly. Map the non-zero exit codes to the most important failure modes.

Send output to stdout. The primary output for your command should go to stdout. Anything that is machine readable should also go to stdout—this is where piping sends things by default.

Send messaging to stderr. Log messages, errors, and so on should all be sent to stderr. This means that when commands are piped together, these messages are displayed to the user and not fed into the next command.

"Successfully compiled" is displayed to the user and should not be piped to the next command, so it is reasonable to output it to stderr.

This is an excellent CLI design guide, which I believe is worth referring to: https://clig.dev/

@SocketSomeone
Copy link
Author

@magic-akari Thank you for attention and advice! We will try to use exit code! I think it can be closed.

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

Successfully merging this pull request may close these issues.

4 participants