Skip to content

fix: don't print empty line to stderr when Exit message is empty#2310

Merged
dearchap merged 1 commit intourfave:mainfrom
Yanhu007:fix/exit-empty-message
Apr 16, 2026
Merged

fix: don't print empty line to stderr when Exit message is empty#2310
dearchap merged 1 commit intourfave:mainfrom
Yanhu007:fix/exit-empty-message

Conversation

@Yanhu007
Copy link
Copy Markdown
Contributor

Fixes #2263

Problem

HandleExitCoder unconditionally prints the error to ErrWriter, causing an empty line on stderr when Exit("", code) is used:

cli.Exit("", exitError.ExitCode()) // prints "\n" to stderr

This was introduced in #2237.

Fix

Check if the error message is non-empty before printing to ErrWriter. The exit code is still passed to OsExiter regardless.

Test

Added TestHandleExitCoder_ExitCoderEmptyMessage to verify no output is written when the message is empty.

HandleExitCoder unconditionally prints the error to ErrWriter,
causing an empty line on stderr when Exit("", code) is used.

Check if the error message is non-empty before printing.
Add test to verify no output for empty exit messages.

Fixes urfave#2263
@Yanhu007 Yanhu007 requested a review from a team as a code owner April 12, 2026 20:06
@dearchap dearchap merged commit efc6352 into urfave:main Apr 16, 2026
8 of 9 checks passed
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

Successfully merging this pull request may close these issues.

v3.6.2 adds empty line to stderr when cli.Exit is called with empty message

2 participants