Skip to content

Skip invalid Rust toolchains instead of failing#1699

Merged
j178 merged 2 commits intomasterfrom
copilot/fix-invalid-rust-toolchain-issue
Feb 27, 2026
Merged

Skip invalid Rust toolchains instead of failing#1699
j178 merged 2 commits intomasterfrom
copilot/fix-invalid-rust-toolchain-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

If any rustup toolchain has a broken rustc binary (e.g. a partially-built stage0 sysroot registered via rustup), prek would fail entirely when trying to select a suitable toolchain, even if many valid toolchains were available.

Closes #1695

Changes

  • rustup.rs: In both list_installed_toolchains() and list_system_toolchains(), replace try_collect() with filter_map() so that toolchains whose rustc --version fails are skipped with a warn! log rather than propagating the error. The overall operation succeeds as long as at least one valid toolchain exists.
// Before: one failure poisons the entire stream
.try_collect()
.await?

// After: bad toolchains are warned and skipped
.filter_map(async move |result| match result {
    Ok(info) => Some(info),
    Err(e) => {
        warn!("Skipping invalid toolchain: {e:#}");
        None
    }
})
.collect()
.await
Original prompt

This section details on the original issue you should resolve

<issue_title>One invalid Rust toolchain causes prek to fail</issue_title>
<issue_description>### Summary

When running a Rust-based hook, I've got the following error:

error: Failed to install hook `oxipng`
  caused by: Failed to install rust
  caused by: Failed to read version from /home/m4tx/projects/rust/build/host/stage0-sysroot/bin/rustc
  caused by: Run command `rustc version` failed
  caused by: No such file or directory (os error 2)

This was very concerning for me at first, since /home/m4tx/projects is a very arbitrary path that I happen to store various repositories in, and I would never expect prek to look for anything in there. Running prek with -vvv did shine some light on this:

2026-02-26T16:45:23.963699Z TRACE Executing `/home/m4tx/.rustup/toolchains/nightly-2025-07-03-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.963942Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.42.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.964608Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.57.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.964848Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.60-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.965053Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.64.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.965181Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.70.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.965471Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.75.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.966651Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.77.2-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.972872Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.975137Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.79.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.977357Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.80.1-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.977749Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.81.0-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.977995Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.84.1-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.978252Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.85-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.978423Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.85.1-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.978681Z TRACE Executing `/home/m4tx/.rustup/toolchains/1.93-x86_64-unknown-linux-gnu/bin/rustc --version`
2026-02-26T16:45:23.983378Z TRACE Executing `/home/m4tx/projects/rust/build/host/stage0-sysroot/bin/rustc --version`

Turns out that I was trying to compile Rust from scratch, which resulted in the toolchain being added to rustup. For the next 6 months ran into any issues because of this (since I had a number of other perfectly working toolchains installed) until I tried prek. Removing the problematic toolchain from rustup has fixed the problem.

I don't think that prek should fail on any when it encounters failure using any toolchain; rather, I would expect it to work if at least one Rust toolchain is usable.

Willing to submit a PR?

  • Yes — I’m willing to open a PR to fix this.

Platform

Arch Linux, Linux 6.12.74-1-lts x86_64 GNU/Linux

Version

prek 0.3.3

.pre-commit-config.yaml

repos:
  - repo: https://github.com/oxipng/oxipng
    rev: v9.1.4
    hooks:
      - id: oxipng
        args: ["-o", "max", "--strip", "safe", "--alpha"]

Log file

2026-02-26T16:45:23.937725Z DEBUG prek: 0.3.3
2026-02-26T16:45:23.937755Z DEBUG Args: ["prek", "-vvv"]
2026-02-26T16:45:23.938885Z TRACE get_root: close time.busy=1.10ms time.idle=2.87µs
2026-02-26T16:45:23.938914Z DEBUG Git root: /home/m4tx/projects/m4txblog
2026-02-26T16:45:23.938928Z TRACE Executing `/usr/bin/git ls-files --unmerged`
2026-02-26T16:45:23.939978Z DEBUG Found workspace root at `/home/m4tx/projects/m4txblog`
2026-02-26T16:45:23.939988Z TRACE Include selectors: ``
2026-02-26T16:45:23.939993Z TRACE Skip selectors: ``
2026-02-26T16:45:23.940045Z DEBUG discover{root="/home/m4tx/projects/m4txblog" config=None refresh=false}: Loaded workspace from cache
2026-02-26T16:45:23.940061Z DEBUG discover{root="/home/m4tx/projects/m4txblog" config=None refresh=false}: Loading project configuration path=.pre-commit-config.yaml
2026-02-26T16:45:23.940757Z TRACE discover{root="/home/m4tx/projects/m4txblog" config=None refresh=false}: close time.busy=748µs time.idle=1.18µs
2026-02-26T16:45:23.940780Z TRACE Executing `/usr/bin/git diff --exit-code --name-only -z /home/m4tx/projects/m4txblog/.pre-commit-config.yaml`
2026-02-26T1...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes j178/prek#1695

<!-- START COPILOT CODING AGENT TIPS -->
---

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security)

Copilot AI changed the title [WIP] Fix invalid Rust toolchain causing prek to fail Skip invalid Rust toolchains instead of failing Feb 27, 2026
@j178 j178 marked this pull request as ready for review February 27, 2026 14:48
@j178 j178 self-requested a review as a code owner February 27, 2026 14:48
Copilot AI review requested due to automatic review settings February 27, 2026 14:48
@j178 j178 added the bug Something isn't working label Feb 27, 2026
@j178 j178 enabled auto-merge (squash) February 27, 2026 14:48
@j178 j178 disabled auto-merge February 27, 2026 14:49
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 43.75000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.55%. Comparing base (a64312f) to head (30a9d81).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/languages/rust/rustup.rs 43.75% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1699      +/-   ##
==========================================
+ Coverage   90.37%   91.55%   +1.18%     
==========================================
  Files          96       96              
  Lines       18880    18892      +12     
==========================================
+ Hits        17062    17296     +234     
+ Misses       1818     1596     -222     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves Rust toolchain selection so prek can continue when a rustup-registered toolchain has a broken rustc (e.g., partial stage0 sysroot), instead of failing the entire Rust installer flow.

Changes:

  • Skip toolchains whose rustc --version fails during toolchain enumeration (instead of erroring out).
  • Emit a warn! log when a toolchain is skipped.

@j178 j178 merged commit e290094 into master Feb 27, 2026
53 checks passed
@j178 j178 deleted the copilot/fix-invalid-rust-toolchain-issue branch February 27, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One invalid Rust toolchain causes prek to fail

3 participants