Skip to content

Conversation

@omskscream
Copy link
Contributor

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 Result it was not straightforward. Probably needs well-thought refactoring, which is out of scope of this PR.

r? @weihanglo

@rustbot rustbot added A-crate-dependencies Area: [dependencies] of any kind A-registries Area: registries S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2026
Copy link
Member

@weihanglo weihanglo left a 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 :)

View changes since this review

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
Copy link
Member

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 note and help levels 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`

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\
Copy link
Member

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)

[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"`
Copy link
Member

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"`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-crate-dependencies Area: [dependencies] of any kind A-registries Area: registries S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants