From f283621e1948d2c1ee3aaa42c2d490f74a106684 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 2 Mar 2026 15:27:23 -0600 Subject: [PATCH 1/2] test: Add unknown arg init test --- tests/suite/cli_rustup_init_ui.rs | 26 +++++++++++++ .../rustup_init_unknown_arg.stderr.term.svg | 37 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg diff --git a/tests/suite/cli_rustup_init_ui.rs b/tests/suite/cli_rustup_init_ui.rs index 676b77c014..1f8cda6708 100644 --- a/tests/suite/cli_rustup_init_ui.rs +++ b/tests/suite/cli_rustup_init_ui.rs @@ -27,6 +27,27 @@ fn test_help(name: &str, args: &[&str]) { .stderr_eq(""); } +#[track_caller] +fn test_error(name: &str, args: &[&str]) { + let home = Path::new(env!("CARGO_TARGET_TMPDIR")).join("home-ro"); + create_dir_all(&home).unwrap(); + + let rustup_init = snapbox::cmd::cargo_bin!("rustup-init"); + Command::new(rustup_init) + .env("RUSTUP_TERM_COLOR", "always") + // once installed rustup asserts the presence of ~/.rustup/settings.toml if + // Config is instantiated. + .env("HOME", &home) + .args(args) + .assert() + .failure() + .stdout_eq("") + .stderr_eq(Data::read_from( + Path::new(&format!("tests/suite/cli_rustup_ui/{name}.stderr.term.svg")), + None, + )); +} + #[track_caller] #[cfg(not(target_os = "windows"))] // On windows, we don't use rustup-init.sh fn test_sh_help(name: &str, args: &[&str]) { @@ -57,6 +78,11 @@ fn rustup_init_help_flag() { test_help("rustup_init_help_flag", &["--help"]); } +#[test] +fn rustup_init_unknown_arg() { + test_error("rustup_init_unknown_arg", &["--random"]); +} + #[test] #[cfg(not(target_os = "windows"))] // On windows, we don't use rustup-init.sh fn rustup_init_sh_help_flag() { diff --git a/tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg b/tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg new file mode 100644 index 0000000000..adc58f25a1 --- /dev/null +++ b/tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg @@ -0,0 +1,37 @@ + + + + + + + error: /x1b[1m/x1b[91merror:/x1b[0m unexpected argument '/x1b[1m/x1b[33m--random/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'. + + + + + + + + From 324e3a525a8d2a92853017926550334608276e9d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 2 Mar 2026 16:11:02 -0600 Subject: [PATCH 2/2] fix(cli): Style CLI errors in init mode By rolling back `tracing-subscriber` for now Fixes #4731 --- Cargo.lock | 57 +++++++++++++------ Cargo.toml | 4 +- .../rustup_init_unknown_arg.stderr.term.svg | 13 +++-- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d44880cc69..018e6a7222 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,7 +237,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" dependencies = [ "memchr", - "regex-automata", + "regex-automata 0.4.14", "serde", ] @@ -1364,11 +1364,11 @@ dependencies = [ [[package]] name = "matchers" -version = "0.2.0" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -1444,11 +1444,12 @@ dependencies = [ [[package]] name = "nu-ansi-term" -version = "0.50.3" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" dependencies = [ - "windows-sys 0.61.2", + "overload", + "winapi", ] [[package]] @@ -1635,6 +1636,12 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "percent-encoding" version = "2.3.2" @@ -1753,7 +1760,7 @@ dependencies = [ "rand 0.9.2", "rand_chacha 0.9.0", "rand_xorshift", - "regex-syntax", + "regex-syntax 0.8.10", "rusty-fork", "tempfile", "unarray", @@ -1936,8 +1943,17 @@ checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.14", + "regex-syntax 0.8.10", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -1948,9 +1964,15 @@ checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.10", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.10" @@ -2922,13 +2944,16 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.32.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac28f2d093c6c477eaa76b23525478f38de514fa9aeb1285738d4b97a9552fc" +checksum = "1e6e5658463dd88089aba75c7791e1d3120633b1bfde22478b28f625a9bb1b8e" dependencies = [ "js-sys", "opentelemetry", + "opentelemetry_sdk", + "rustversion", "smallvec", + "thiserror 2.0.18", "tracing", "tracing-core", "tracing-log", @@ -2938,14 +2963,14 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.22" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ "matchers", "nu-ansi-term", "once_cell", - "regex-automata", + "regex", "sharded-slab", "smallvec", "thread_local", diff --git a/Cargo.toml b/Cargo.toml index c1784fcf19..6994070866 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,9 @@ toml = "1.0" tracing = "0.1" tracing-log = "0.2" tracing-opentelemetry = { version = "0.32", optional = true } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } +# Newer versions render ANSI escape codes, causing CLI errors to be ugly +# See also https://github.com/tokio-rs/tracing/issues/3369 +tracing-subscriber = { version = "=0.3.19", features = ["env-filter"] } url = "2.4" wait-timeout = "0.2" xz2 = "0.1.3" diff --git a/tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg b/tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg index adc58f25a1..b438540aec 100644 --- a/tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg +++ b/tests/suite/cli_rustup_ui/rustup_init_unknown_arg.stderr.term.svg @@ -1,8 +1,13 @@ - +