-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(patch): clean up patch-related error messages #16498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(patch): clean up patch-related error messages #16498
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request. Looks really nice!
I was thinking about (and tried) moving this portion of error messages directly to the annotate snippets #15944, but with several functions returning Result it was not straightforward. Probably needs well-thought refactoring, which is out of scope of this PR.
Yeah that one definitely need more legwork :)
| Caused by: | ||
| The patch location `[ROOT]/foo/bar` contains a `bar` package with version `0.1.0`, but the patch definition in `[ROOT]/foo/Cargo.toml` requires `^0.1.1`. | ||
| Check that the version in the patch location is what you expect, and update the patch definition to match. | ||
| [ERROR] patch `bar` version mismatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clean-up!
Some minor nits:
- First letter should be lowercase.
- We could have
noteandhelplevels here maybe, such as
error: patch `bar` version mismatch
note: patch location contains version `0.1.0`, but patch definition requires `^0.1.1`
help: check patch location `[ROOT]/foo/bar`
help: check `bar` patch definition for `https://github.com/rust-lang/crates.io-index`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments (and sorry for the delay in addressing them -- life happens).
Strangely, putting keywords to the message manually for some reason did not occur to me, but now I know that there's a way 🙂
| vers.sort(); | ||
| let versions: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect(); | ||
| return Poll::Ready(Err(anyhow::anyhow!( | ||
| "patch for `{}` in `{}` resolved to more than one candidate\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to quite the second one (source)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it's similar to displaying various context::Definition in messages that were discussed in #16407.
Here SourceId is used and for some kinds it uses backticks in its Display implementation, for others don't.
I've added a separate test using git repository (commit#418bb33) to showcase when backticks would be preferred. So I don't think it will make sense to remove them here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. We can leave it for future improvements. Thanks for adding a test!
tests/testsuite/patch.rs
Outdated
| [ERROR] patch for `bar` in `registry `alternative`` resolved to more than one candidate | ||
| Found versions: 0.1.0, 0.1.1 | ||
| Check `bar` patch definition for `https://github.com/rust-lang/crates.io-index` in `[ROOT]/foo/Cargo.toml` | ||
| For example, select only one package using `version = "=0.1.1"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- we don't need to quote "registry
alternative" maybe?
What about this?
error: patch for `bar` in registry `alternative` resolved to more than one candidate
note: found versions: 0.1.0, 0.1.1
help: check `bar` patch definition for `https://github.com/rust-lang/crates.io-index` in `[ROOT]/foo/Cargo.toml`
help: select only one package, for example with `version = "=0.1.1"`
…to several candidates
…le resolved candidates
e5c05f7 to
8bbb642
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Appreciate the help!
| vers.sort(); | ||
| let versions: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect(); | ||
| return Poll::Ready(Err(anyhow::anyhow!( | ||
| "patch for `{}` in `{}` resolved to more than one candidate\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. We can leave it for future improvements. Thanks for adding a test!
Update cargo submodule 14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f 2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000 - chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548) - Increase cache_lock test timeout (rust-lang/cargo#16545) - iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506) - chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543) - test(build-std): adjust snapshot (rust-lang/cargo#16539) - chore: bump to 0.96.0 (rust-lang/cargo#16538) - fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221) - fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535) - fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536) - feat(lints): Add non_kebab_case_bin lint (rust-lang/cargo#16524) - fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533) - fix(patch): clean up patch-related error messages (rust-lang/cargo#16498) - Store artifact deps in build unit dir (rust-lang/cargo#16519) - refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
Update cargo submodule 14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f 2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000 - chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548) - Increase cache_lock test timeout (rust-lang/cargo#16545) - iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506) - chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543) - test(build-std): adjust snapshot (rust-lang/cargo#16539) - chore: bump to 0.96.0 (rust-lang/cargo#16538) - fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221) - fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535) - fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536) - feat(lints): Add non_kebab_case_bin lint (rust-lang/cargo#16524) - fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533) - fix(patch): clean up patch-related error messages (rust-lang/cargo#16498) - Store artifact deps in build unit dir (rust-lang/cargo#16519) - refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
Update cargo submodule 14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f 2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000 - chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548) - Increase cache_lock test timeout (rust-lang/cargo#16545) - iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506) - chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543) - test(build-std): adjust snapshot (rust-lang/cargo#16539) - chore: bump to 0.96.0 (rust-lang/cargo#16538) - fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221) - fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535) - fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536) - feat(lints): Add non_kebab_case_bin lint (rust-lang/cargo#16524) - fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533) - fix(patch): clean up patch-related error messages (rust-lang/cargo#16498) - Store artifact deps in build unit dir (rust-lang/cargo#16519) - refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
Update cargo submodule 14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f 2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000 - chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548) - Increase cache_lock test timeout (rust-lang/cargo#16545) - iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506) - chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543) - test(build-std): adjust snapshot (rust-lang/cargo#16539) - chore: bump to 0.96.0 (rust-lang/cargo#16538) - fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221) - fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535) - fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536) - feat(lints): Add non_kebab_case_bin lint (rust-lang/cargo#16524) - fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533) - fix(patch): clean up patch-related error messages (rust-lang/cargo#16498) - Store artifact deps in build unit dir (rust-lang/cargo#16519) - refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
Update cargo submodule 14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f 2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000 - chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548) - Increase cache_lock test timeout (rust-lang/cargo#16545) - iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506) - chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543) - test(build-std): adjust snapshot (rust-lang/cargo#16539) - chore: bump to 0.96.0 (rust-lang/cargo#16538) - fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221) - fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535) - fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536) - feat(lints): Add non_kebab_case_bin lint (rust-lang/cargo#16524) - fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533) - fix(patch): clean up patch-related error messages (rust-lang/cargo#16498) - Store artifact deps in build unit dir (rust-lang/cargo#16519) - refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
What does this PR try to resolve?
This is a follow-up for #16407.
This PR is supposed to make patch-related error messages closer to the desired style, remove unnecessary(?) context wrappings, and fix a few minor issues in code.
I tried to restructure some of the error messages to include the values from
.context()where I thought it would make sense. Obvious duplications (e.g. repository url of the patch) were removed.I tried to rephrase some of the error messages to sound closer to the desired style and to ease future migration to rustc's error reporter.
How to test and review this PR?
Test changes should demonstrate the intended behavior change.
Suggestions on how to make messages even better are obviously welcome.
Note
I was thinking about (and tried) moving this portion of error messages directly to the annotate snippets #15944, but with several functions returning
Resultit was not straightforward. Probably needs well-thought refactoring, which is out of scope of this PR.r? @weihanglo