Skip to content

CLI errors show escape codes #4731

@epage

Description

@epage

Verification

Problem

For some CLI errors, rustup shows escape codes while others show colored output.

Steps

$ cargo run -- show --jkhjkh
warning: ignoring 'build.analysis' config, pass `-Zbuild-analysis` to enable it
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/rustup-init show --jkhjkh`
error: \x1b[1m\x1b[91merror:\x1b[0m unexpected argument '\x1b[1m\x1b[33mshow\x1b[0m' found

\x1b[1m\x1b[92mUsage:\x1b[0m \x1b[1m\x1b[96mrustup-init[EXE]\x1b[0m \x1b[36m[OPTIONS]\x1b[0m

For more information, try '\x1b[1m\x1b[96m--help\x1b[0m'.
$ cargo run --config env.RUSTUP_FORCE_ARG0=\'rustup\' -- check --no-self-update=foo
warning: ignoring 'build.analysis' config, pass `-Zbuild-analysis` to enable it
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/rustup-init check --no-self-update=foo`
error: unexpected value 'foo' for '--no-self-update' found; no more were expected

Usage: rustup[EXE] check --no-self-update

For more information, try '--help'.

Possible Solution(s)

No response

Notes

I'm assuming something is weird about the two streams being selected between at

if [
InvalidSubcommand,
UnknownArgument,
DisplayHelpOnMissingArgumentOrSubcommand,
]
.contains(&err.kind())
{
write!(process.stdout().lock(), "{}", err.render().ansi())?;
} else {
write!(process.stderr().lock(), "{}", err.render().ansi())?;
}
return Ok(ExitCode::FAILURE);

Rustup version

$ cargo run -- --version
warning: ignoring 'build.analysis' config, pass `-Zbuild-analysis` to enable it
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/rustup-init --version`
rustup-init 1.29.0 :: 1.28.2+518 (a373a2c8c 2026-02-24)

Installed toolchains

N/A

OS version

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions