-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat (patch): Display where the patch was defined in patch-related error messages #16407
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
base: master
Are you sure you want to change the base?
feat (patch): Display where the patch was defined in patch-related error messages #16407
Conversation
840bde1 to
ecc6ec6
Compare
|
Thanks for the PR! Haven't really started the review, though I feel like for |
|
Note that while we ask for small commits, we ask for them to be atomic, including not having dead code, see https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request For instance, |
Thank you for this comment! I was looking for the cargo specific commit guidance, but somehow missed this, even though it's in the repo itself. |
ecc6ec6 to
8051724
Compare
Thank you for this comment! I thought about this while working on the implementation. Taking into account the above, I now don't see anything specific that is against using pub enum PatchLocation {
/// Defined in a manifest.
Manifest(PathBuf),
/// Defined in cargo configuration.
Config(Definition),
} |
Is that assumption true? I'm not seeing documentation or any tests for it, so I;'m unsure.
I see a lot of value in reusing our existing definition and keeping code paths as similar as possible. I'd like to better understand why CLI would be handled differently. |
I wasn't sure for the same reasons, so I'll try adding more patch specific tests for different config locations. Not sure if it will make sense to test
I think initially it was a way to separate file-based patch locations from "ephemeral" in my mind to clarify the requirements. Maybe it was unnecessary, but helped me to grasp the concept and proceed with the pull request 🙂 |
No need to test this.
I guess the impression was also from the [patch] section doc that only talks about CLI and file configs but environment variable, and the |
…es and is ignored
… different places resolve to same version
…g file provided via cli
8051724 to
8244bb1
Compare
| // copy of the [mismatched_version_from_cli_config] cli options using conversion to env | ||
| // described in https://doc.rust-lang.org/cargo/reference/config.html#environment-variables | ||
| p.cargo("check") | ||
| .env("CARGO_PATCH_CRATES_IO_BAR_PATH", "bar") |
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.
That is unfortunate 😞.
I guess it was ignored because the subtable got interpreted as [patch.crates.io]. If it were a complete registry name without any punctuation, it may work.
| patch for `bar` in `registry `alternative`` resolved to more than one candidate | ||
| Found versions: 0.1.0, 0.1.1 | ||
| Update the patch definition to select only one package. | ||
| Update the patch definition in `[ROOT]/foo/Cargo.toml` to select only one package. | ||
| For example, add an `=` version requirement to the patch definition, such as `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.
non-blocking (likely shouldn't even be attempted in this PR to limit scope creep): these error messages are not in the style we're aiming for. The path is inserted in this PR where it makes sense for english but it further exacerbates the problem and could potentially make the lines really long, breaking up the text and making it harder to read.
Eventually we want to migrate to rustc's error reporter (#15944) which will help a lot (e,g, the patch location would be a source-less Origin) but that is a ways off.
It would be nice for us (doesn't have to be this PR's author) to do a follow up to clean these up.
src/cargo/core/registry.rs
Outdated
| name, | ||
| duplicate_locations.join(", ") | ||
| )) | ||
| .context(format!("failed to resolve patches in `{}`", url)); |
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.
Unless there is a driving reason to do so, I think it would be better to not add this additional context through context as it makes things less flexible for how we could improve the wording of the error messages, see also a39d5c0#r2628751019
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.
I was thinking about unifying the error context for similar patch resolve problems. There are two similar messages with the same additional context in the very same function on lines L447 and L466
I fixed preposition in -> for in the additional commit to match those two exactly. Although, I see the reasoning. Will make sense to remove this extra context from here and from two other places mentioned above as well?
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.
Those should be cleaned up (oof, one even duplicates url) but that would not be blocking for this PR and would likely be best left to another PR to avoid adding extra review rounds just to get those "right"
|
Thanks for your work on this! Adding this context will be really helpful to users! |
|
FYI feel free to rewrite commits. It is usually easier to come back and review when I'm able to look at atomic commits rather than having to keep in mind how future commits might change what I'm looking at. |
…r resolving "patch" dependency overrides
…atches found for this patch definition
… matches for a patch definition in the specified location
…ce is the same as dependency source
…multiple patch definitions resolving to the same version
99aaa89 to
5ebec7d
Compare
What does this PR try to resolve?
Closes #13952
This PR adds location information of where each 'patch' was defined to the dependency override algorithm. Currently there're three possible sources: manifest
Cargo.toml, one of the configuration files (listed here) or CLI option--config 'patch.crates-io.rand.path="rand"'(source).Preserving location of where the patch was defined should simplify troubleshooting of incorrect or incompatible dependency override configuration.
This PR does not change:
cargo::core::Workspace::root_patchfunction)How to test and review this PR?
I suppose test changes should demonstrate the intended behavior change. Few earlier commits do not contain test changes because they do not change visible behavior of cargo but allow to proceed with the ones that do.