Skip invalid Rust toolchains instead of failing#1699
Merged
Conversation
Co-authored-by: j178 <[email protected]>
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
approved these changes
Feb 27, 2026
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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 --versionfails during toolchain enumeration (instead of erroring out). - Emit a
warn!log when a toolchain is skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If any rustup toolchain has a broken
rustcbinary (e.g. a partially-built stage0 sysroot registered via rustup),prekwould fail entirely when trying to select a suitable toolchain, even if many valid toolchains were available.Closes #1695
Changes
rustup.rs: In bothlist_installed_toolchains()andlist_system_toolchains(), replacetry_collect()withfilter_map()so that toolchains whoserustc --versionfails are skipped with awarn!log rather than propagating the error. The overall operation succeeds as long as at least one valid toolchain exists.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:
This was very concerning for me at first, since
/home/m4tx/projectsis 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-vvvdid shine some light on this: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
prekshould 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?
Platform
Arch Linux, Linux 6.12.74-1-lts x86_64 GNU/Linux
Version
prek 0.3.3
.pre-commit-config.yaml
Log file