Skip to content

Fix(error): Printing a new line to avoid overwriting error code after \r - #17373

Open
Suryansh-Dey wants to merge 1 commit into
rust-lang:masterfrom
Suryansh-Dey:newline
Open

Fix(error): Printing a new line to avoid overwriting error code after \r#17373
Suryansh-Dey wants to merge 1 commit into
rust-lang:masterfrom
Suryansh-Dey:newline

Conversation

@Suryansh-Dey

@Suryansh-Dey Suryansh-Dey commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

Closes #17343
Changes:
Added newline using writeln!(gctx.shell().err());
Reason:
Could have used format!("\n{err}") but if there's an in-progress status line, gctx.shell().err() would erase it then print a newline. If you want I can switch to format option but this feels practically safer.

How to test and review this PR?

  • Run cargo test -p cargo --test testsuite -- run::exit_code run::exit_code_verbose And both the tests passes.
  • Make a program in windows
fn main() {
    print!("hewwo\r");
    std::process::exit(1);
}

then run cargo run. It prints error message just below.
image
(Compiling for windows almost killed my laptop)

Before (current cargo on windows)

image

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. Command-run S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2026
@rustbot

rustbot commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @epage, @weihanglo
  • @epage, @weihanglo expanded to epage, weihanglo
  • Random selection from epage, weihanglo

if is_quiet {
CliError::code(exit_code)
} else {
// Print a newline to stderr due to [this](https://github.com/rust-lang/cargo/issues/17343#issuecomment-5242201054).

@epage epage Aug 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For myself, I prefer describing why inline instead of pointing to a comment, like

Ensure a newline between user and cargo's output, especially with trailing "\r"

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should I keep the URL in more like this?:
Ensure a newline between user and cargo's output, especially with trailing "\r". More

Once I get your opinion I am ready to proceed

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

Labels

A-cli Area: Command-line interface, option parsing, etc. Command-run S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo run "process didn't exit successfully" overwrites last line of a program that uses carriage return

3 participants