Skip to content

The error reading rustc version message could be improved #3607

Open

Description

@rustrust

Problem

M1 macOS 12.4.1

> rustup update
info: syncing channel updates for 'stable-aarch64-apple-darwin'
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: syncing channel updates for 'nightly-aarch64-apple-darwin'
info: checking for self-update

      stable-aarch64-apple-darwin unchanged - rustc 1.75.0 (82e1608df 2023-12-21)
  stable-x86_64-unknown-linux-gnu unchanged - (error reading rustc version)
     nightly-aarch64-apple-darwin unchanged - rustc 1.77.0-nightly (89e2160c4 2023-12-27)

Steps

rustup update with stable-x86_64-unknown-linux-gnu toolchain

Possible Solution(s)

No response

Notes

No response

Rustup version

rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.75.0 (82e1608df 2023-12-21)`


### Installed toolchains

```console
Default host: aarch64-apple-darwin
rustup home:  /Users/foobar/.rustup

installed toolchains
--------------------

stable-aarch64-apple-darwin (default)
stable-x86_64-unknown-linux-gnu
nightly-aarch64-apple-darwin
1.60.0-aarch64-apple-darwin
1.61.0-aarch64-apple-darwin
1.65.0-aarch64-apple-darwin
1.70.0-aarch64-apple-darwin

installed targets for active toolchain
--------------------------------------

aarch64-apple-darwin
aarch64-unknown-linux-gnu
x86_64-pc-windows-msvc

active toolchain
----------------

stable-aarch64-apple-darwin (default)
rustc 1.75.0 (82e1608df 2023-12-21)

Activity

  1. rami3l commented on Jan 2, 2024

    @rami3l
    Member

    @rustrust Thanks for filing this issue!

    It seems that you're using Rust on macOS, so stable-x86_64-unknown-linux-gnu can't normally be a running host triple.
    The error reading rustc version error indicates exactly that: rustup tries to run rustc to find out the exact version, but you cannot run x64 Linux binaries on ARM64 macOS.

    Maybe you're setting up cross compilation? In that case, you should add a new target triple under your aarch64-apple-darwin toolchain, like you did with aarch64-unknown-linux-gnu.

    Please feel free to tell me if have further concerns.
    Have a nice day!

  2. rustrust commented on Jan 2, 2024

    @rustrust
    Author

    To prevent others from being perplexed by this in the future, maybe a different error message (one not using the word "error") might be helpful here?

  3. rami3l commented on Jan 2, 2024

    @rami3l
    Member

    @rustrust This error only indicates that rustup failed to invoke rustc, and no further info can be provided.

    IRL this can happen for multiple reasons, e.g. the permission is not correct, the binary is corrupted, etc.

    Although accidentally installing the binary built for another platform is indeed another possible reason, this particular situation should be quite rare IMHO.

    Do you happen to have any specific error message in mind?

  4. djc commented on Jan 2, 2024

    @djc
    Contributor

    IRL this can happen for multiple reasons, e.g. the permission is not correct, the binary is corrupted, etc.

    It would probably be helpful if we can propagate/show the exact error condition that triggered this.

  5. added this to the On Deck milestone on Apr 15, 2024
  6. changed the title [-] stable-x86_64-unknown-linux-gnu unchanged - (error reading rustc version)[/-] [+]The `error reading rustc version` message could be improved[/+] on Apr 15, 2024
  7. rami3l commented on Apr 15, 2024

    @rami3l
    Member

    Reopening since it's still valuable to enhance the error message.

  8. reopened this on Apr 15, 2024
  9. modified the milestones: On Deck, 1.28.0 on Apr 15, 2024
  10. modified the milestones: 1.28.0, 1.29.0 on Jul 16, 2024
  11. Bogay commented on Mar 5, 2026

    @Bogay
    Contributor

    The error message comes from Toolchain::rustc_version. I can see there are several ignored std::io::Errors and one anyhow::Error from Toolchain::create_command. I've tested it in my fork (Bogay@2ceb33c) and here are some output examples of Toolchain::rustc_version by rustup show -v:

    • (error reading rustc version: Exec format error (os error 8))
    • (error reading rustc version: exit status: 42)
    • (error reading rustc version: Permission denied (os error 13))

    Is it acceptable to simply append the captured error to the output format string? I'm concerned that they become too long in some cases.

    rustup/src/toolchain.rs

    Lines 283 to 329 in 28d1352

    /// Infallible function that describes the version of rustc in an installed distribution
    #[tracing::instrument(level = "trace")]
    pub fn rustc_version(&self) -> String {
    match self.create_command("rustc") {
    Ok(mut cmd) => {
    cmd.arg("--version");
    cmd.stdin(Stdio::null());
    cmd.stdout(Stdio::piped());
    cmd.stderr(Stdio::piped());
    self.set_ldpath(&mut cmd);
    // some toolchains are faulty with some combinations of platforms and
    // may fail to launch but also to timely terminate.
    // (known cases include Rust 1.3.0 through 1.10.0 in recent macOS Sierra.)
    // we guard against such cases by enforcing a reasonable timeout to read.
    let mut line1 = None;
    if let Ok(mut child) = cmd.spawn() {
    let timeout = Duration::new(10, 0);
    match child.wait_timeout(timeout) {
    Ok(Some(status)) if status.success() => {
    let out = child
    .stdout
    .expect("Child::stdout requested but not present");
    let mut line = String::new();
    if BufReader::new(out).read_line(&mut line).is_ok() {
    let lineend = line.trim_end_matches(&['\r', '\n'][..]).len();
    line.truncate(lineend);
    line1 = Some(line);
    }
    }
    Ok(None) => {
    let _ = child.kill();
    return String::from("(timeout reading rustc version)");
    }
    Ok(Some(_)) | Err(_) => {}
    }
    }
    if let Some(line1) = line1 {
    line1
    } else {
    String::from("(error reading rustc version)")
    }
    }
    Err(_) => String::from("(rustc does not exist)"),
    }
    }

  12. rami3l commented on Mar 5, 2026

    @rami3l
    Member

    @Bogay I think if the attacker cannot write arbitrary output into our error message then we'd be good. Although I know io::Error is open-ended, it seems that Command::spawn() can only throw some of them, so you have a very limited set of output to handle.

    Would you mind submitting a PR (even in draft state) so we can have a further look?

  13. Bogay commented on Mar 5, 2026

    @Bogay
    Contributor

    @rami3l Sure, I have opened a draft PR.

    it seems that Command::spawn() can only throw some of them, so you have a very limited set of output to handle.

    I agree that the error messages can be improved for some common cases. However, I am not sure which errors should be handled. As per discussion in rust-lang/rust#108213, it seems that rust std does not guarantee returned errors of those methods.

  14. sftse commented on Apr 9, 2026

    @sftse
    stable-x86_64-unknown-linux-gnu updated - rustc 1.94.1 (e408947bf 2026-03-25) (from rustc 1.93.0 (254b59607 2026-01-19))
    stable-x86_64-unknown-linux-musl updated - (error reading rustc version) (from (error reading rustc version))
    nightly-x86_64-unknown-linux-gnu updated - rustc 1.96.0-nightly (900485642 2026-04-08) (from rustc 1.95.0-nightly (efc9e1b50 2026-02-06))
    nightly-x86_64-unknown-linux-musl updated - (error reading rustc version) (from (error reading rustc version))
    

    It seems that you're using Rust on macOS, so stable-x86_64-unknown-linux-gnu can't normally be a running host triple.
    The error reading rustc version error indicates exactly that: rustup tries to run rustc to find out the exact version, but you cannot run x64 Linux binaries on ARM64 macOS.

    Is there a reason why unknown-linux-musl would error on Linux while unknown-linux-gnu succeeds?

    rustup -V
    rustup 1.29.0 (28d1352db 2026-03-05)
    
  15. rami3l commented on Apr 9, 2026

    @rami3l
    Member
    stable-x86_64-unknown-linux-gnu updated - rustc 1.94.1 (e408947bf 2026-03-25) (from rustc 1.93.0 (254b59607 2026-01-19))
    stable-x86_64-unknown-linux-musl updated - (error reading rustc version) (from (error reading rustc version))
    nightly-x86_64-unknown-linux-gnu updated - rustc 1.96.0-nightly (900485642 2026-04-08) (from rustc 1.95.0-nightly (efc9e1b50 2026-02-06))
    nightly-x86_64-unknown-linux-musl updated - (error reading rustc version) (from (error reading rustc version))
    

    It seems that you're using Rust on macOS, so stable-x86_64-unknown-linux-gnu can't normally be a running host triple.
    The error reading rustc version error indicates exactly that: rustup tries to run rustc to find out the exact version, but you cannot run x64 Linux binaries on ARM64 macOS.

    Is there a reason why unknown-linux-musl would error on Linux while unknown-linux-gnu succeeds?

    @sftse See #3254 (comment) and rust-lang/rust#108907.

    The TLDR is to install the musl target, not the musl toolchain, on your system.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions