Skip to content

Improved the test error messages when 'rustc -V' fails - #17108

Merged
weihanglo merged 1 commit into
rust-lang:masterfrom
ranger-ross:better-cargo-test-rustc-failure
Jun 17, 2026
Merged

Improved the test error messages when 'rustc -V' fails#17108
weihanglo merged 1 commit into
rust-lang:masterfrom
ranger-ross:better-cargo-test-rustc-failure

Conversation

@ranger-ross

Copy link
Copy Markdown
Member

What does this PR try to resolve?

While debugging the build issues in rust-lang/rust#155439 I was running into some issues where rustc -V would fail due to windows path limits.
When happens the error message is not super helpful.

  --> src\tools\cargo\tests\build-std\main.rs:95:1
   |
95 | #[cargo_test(build_std_real)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: called `Option::unwrap()` on a `None` value

I added some panic messages which replace the currently less helpful help: line.

I also special cased Windows error code 3221225495 with a dedicated error message since is its not super obvious what is happening I hope to avoid other having to go through the pain of debugging this.

How to test and review this PR?

I tested against the changes in rust-lang/rust#155439 but you could also probably override the rustc on the PATH with something that always returns an error status code.

r? @weihanglo

@rustbot rustbot added the A-testing-cargo-itself Area: cargo's tests label Jun 16, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 16, 2026
Comment thread crates/cargo-test-macro/src/lib.rs Outdated
if exit_code != Some(0) {
let stdout = std::str::from_utf8(&output.stdout).unwrap_or("<invalid utf8>");
let stderr = std::str::from_utf8(&output.stderr).unwrap_or("<invalid utf8>");
let extra = if exit_code.map(|c| c as u32) == Some(3221225495) {

@epage epage Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe this is generally written in hex

Suggested change
let extra = if exit_code.map(|c| c as u32) == Some(3221225495) {
let extra = if exit_code.map(|c| c as u32) == Some(0xC0000017) {

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I dislike having the constant but unsure if it is worth pulling in windows-sys to get the constant

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we have a comment link to the official doc about this exit code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I updated to 0xC0000017. I felt pulling in windows-sys was a bit overkill for a slightly better error message in what I expect to be a rare failure.

Also it seems like this error code is not well documented.
I can see many blog posts about "how to fix windows booting" that mention this error code but could not track down any official documentation on this code 😅

@ranger-ross
ranger-ross force-pushed the better-cargo-test-rustc-failure branch from d269d1e to dfa3c47 Compare June 17, 2026 02:03
@ranger-ross
ranger-ross force-pushed the better-cargo-test-rustc-failure branch from dfa3c47 to 855c844 Compare June 17, 2026 02:05
@weihanglo
weihanglo enabled auto-merge June 17, 2026 02:06
@weihanglo
weihanglo added this pull request to the merge queue Jun 17, 2026
Merged via the queue into rust-lang:master with commit 598ab48 Jun 17, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 17, 2026
Update cargo submodule

7 commits in fe63976b245b8a649c3f2949bf89fdc307bfbae4..598ab48ec328e3e4f5e4e373d8df7264bc8e27cd
2026-06-11 09:17:57 +0000 to 2026-06-17 02:39:50 +0000
- Improved the test error messages when 'rustc -V' fails (rust-lang/cargo#17108)
- test(install): `cargo install` --path honors MSRV (rust-lang/cargo#17102)
- feat(trim-paths): emit `CARGO_TRIM_PATHS_REMAP` for build.rs (rust-lang/cargo#17104)
- Add funding links (rust-lang/cargo#17103)
- fix(diag): Give diagnostics the same display path behavior as rustc (rust-lang/cargo#17101)
- refactor: remove cargo-util-terminal from bump-check exclusions (rust-lang/cargo#17098)
- fix(diag): Report all errors, in order (rust-lang/cargo#17095)
@rustbot rustbot added this to the 1.98.0 milestone Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testing-cargo-itself Area: cargo's tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants