Skip to content
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

Better error message when registry is added to Cargo.toml instead of Cargo config #12576

Closed
BatmanAoD opened this issue Aug 28, 2023 · 3 comments
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-registries Area: registries C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@BatmanAoD
Copy link
Member

BatmanAoD commented Aug 28, 2023

Problem

Alternative registries are added in Cargo-config (e.g. ~/.cargo/config.toml), not in a project's Cargo.toml file.

If a registry is added in Cargo.toml but not used, a helpful warning is printed:

warning: unused manifest key: registries

If, however, a dependency is added that uses the alternate registry, only an error message is shown:

error: failed to parse manifest at `<path>\Cargo.toml`

Caused by:
  no index found for registry: `<name>`

This is actually somewhat confusing: I initially didn't notice that the dependencies section belongs in a different file, so when I got this error, I thought it was a problem with the registry URL or syntax.

Proposed Solution

Multiple possible solutions, with different levels of effort:

  • Change the wording of the no index found message to explicitly mention config.toml. For instance, it could be reworded as registry index was not found in any config.toml file
  • Print the unused manifest keys warning even if the manifest fails to parse (I'm not sure how easy this would be)
  • When the no index found message occurs, explicitly check to see if Cargo.toml has a registries section, and if so, print a separate error message, something like "registries must be defined in config.toml; see https://doc.rust-lang.org/cargo/reference/config.html"
  • Just permit registries to be in either config.toml or Cargo.toml (I'm assuming there's a good reason for not doing this, though).

Notes

No response

@BatmanAoD BatmanAoD added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Aug 28, 2023
@BatmanAoD
Copy link
Member Author

It looks like #12531 might indirectly make it easier to control whether warnings are still printed when there's a hard error, making the 2nd suggestion ("Print the unused manifest keys warning...") more viable.

@weihanglo
Copy link
Member

weihanglo commented Sep 11, 2023

In short term, I feel like the option one is the way to go:

registry index was not found in any configuration: {reg_name}

@rustbot label -S-triage +S-accepted +E-easy +A-error +A-registries

@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-registries Area: registries S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Sep 11, 2023
bors added a commit that referenced this issue Sep 25, 2023
more specific registry index not found msg

### What does this PR try to resolve?

covers #12576

### How should we test and review this PR?

test covers exact text, so a review and passing tests.
@torhovland
Copy link
Contributor

Looks like this issue should be closed as fixed.

@epage epage closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-registries Area: registries C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

No branches or pull requests

4 participants