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

String::from("(error reading rustc version)")
let out = child
.stdout
.expect("Child::stdout requested but not present");
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 we return a string instead of panic here? The doc of rustc_version says it's infallible function

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.

No. If the function panics here it means the Command setup is wrong and this is a programming error, and we should expose the error instead of covering it up.

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.)

.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.

@rami3l
Copy link
Copy Markdown
Member

rami3l commented Apr 9, 2026

Sorry for getting sidetracked for a while... I'll find some time to give it another look.

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