Skip to content

feat(toolchain): include err in rustc_version output#4741

Draft
Bogay wants to merge 4 commits intorust-lang:mainfrom
Bogay:improve-rustc-version-error-message
Draft

feat(toolchain): include err in rustc_version output#4741
Bogay wants to merge 4 commits intorust-lang:mainfrom
Bogay:improve-rustc-version-error-message

Conversation

@Bogay
Copy link
Copy Markdown
Contributor

@Bogay Bogay commented Mar 5, 2026

This PR includes error details in Toolchain::rustc_version so that it's more clear to end-user what happened.

Close #3607

@Bogay Bogay force-pushed the improve-rustc-version-error-message branch from 2ceb33c to b8c00f3 Compare March 5, 2026 19:28
@rami3l rami3l self-assigned this Mar 6, 2026
Copy link
Copy Markdown
Member

@rami3l rami3l left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

View changes since this review

@Bogay Bogay force-pushed the improve-rustc-version-error-message branch from b8c00f3 to 1ad60d1 Compare March 15, 2026 12:28
@Bogay Bogay force-pushed the improve-rustc-version-error-message branch from 1ad60d1 to 44ec134 Compare March 15, 2026 12:57
Copy link
Copy Markdown
Contributor Author

@Bogay Bogay left a comment

Choose a reason for hiding this comment

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

I've added some testcases. But I found some new issues I didn't aware of need to be discussed.

View changes since this review

Comment on lines +1412 to +1418
.with_stdout(snapbox::str![
r#"
...
compiler: (rustc does not exist: [..])
...
"#
])
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.

This test failed (example job) because it the Toolchain::create_command in Toolchain::rustc_version does not return Err even rustc doesn't exist in toolchain. AFAIK it fallback to the rustc in PATH, which I believe related to #3387 . It's also hard to produce a env that don't have rustc in PATH because mock_bin use rustc to compile the binary. (If we can restrict rustup proxy to not use rustc inside PATH, I think that would be easier.)

Copy link
Copy Markdown
Member

@rami3l rami3l Apr 14, 2026

Choose a reason for hiding this comment

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

@Bogay Give this a try:

fs::remove_file(path.join("bin/rustc")).unwrap();
cx.config
  .expect_with_env(&["rustup", "show", "active-toolchain", "--verbose"], [("PATH", ""), ("RUST_RECURSION_COUNT", "1023")])
[..]

The RUST_RECURSION_COUNT is explicitly large to make sure that create_command() bails out.

OTOH if the error string spans multiple lines we might want to capture the first line only.

.is_err();
}

#[cfg(unix)]
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.

I use shell script to mock the exit code of rustc in toolchain, which I think can only be executed on unix. Not sure whether it's acceptable in rustup test suite. 🤔

Copy link
Copy Markdown
Member

@rami3l rami3l Apr 9, 2026

Choose a reason for hiding this comment

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

Thanks for asking! Actually we have mock_bin_src.rs which you can use instead of this dirty hack. You can modify it to make the thing crash in a cross-platform and deterministic way. IIRC the rustc we call in other tests is actually this instead of the real rustc.

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.

Yes. In other tests mock_bin_src.rs is used for mock rustc. However, I don't know how to control args passed to rustc in this testcase. Maybe we can control the exit code using env var? But that's a new pattern which is not used in mock_bin_src.rs.

Copy link
Copy Markdown
Member

@rami3l rami3l Apr 14, 2026

Choose a reason for hiding this comment

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

@Bogay I do think you can try passing an env variable instead. The rustup proxy should pass the env variables down to the mock binary. Just make sure the env var is not super commonly-named to avoid side effects.

Alternatively you can compile a rust binary yourself which is independent from mock_bin_src.rs if that turns out easier for you.

@rami3l

This comment was marked as resolved.

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.

The error reading rustc version message could be improved

2 participants