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

More helpful error message when a stray Cargo.toml is present #13904

Open
kpreid opened this issue May 11, 2024 · 0 comments
Open

More helpful error message when a stray Cargo.toml is present #13904

kpreid opened this issue May 11, 2024 · 0 comments
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-workspaces Area: workspaces C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy S-triage Status: This issue is waiting on initial triage.

Comments

@kpreid
Copy link
Contributor

kpreid commented May 11, 2024

Problem

Newcomers to Cargo occasionally end up with a Cargo.toml file that is irrelevant to the project they're trying to run. (It is often in their home directory; perhaps they ran cargo init not understanding what it does, but that's speculation.) When this happens, they get an error message that doesn't really explain what is going on. An example from today:

$ cargo run
error: failed to parse manifest at '/home/user/Cargo.toml'

Caused by:
  this virtual manifest specifies a 'dependencies' section, which is not allowed

New users don't know what a “virtual manifest” is, and are dealing with too many new concepts already to notice that /home/user/Cargo.toml isn't their project directory, nor do they know that it doesn't make sense to have one there. (And this message doesn't even contain the word “workspace”!)

Proposed Solution

Two parts:

  1. When Cargo produces an error, the error is related to an invalid workspace manifest, and the purported workspace manifest path was found in a parent directory (rather than being the direct output of the locate-project algorithm), produce a message which prints the paths of both manifests rather than only the workspace manifest, with some explanation that these are two different manifests and how each relates to the situation.

  2. If the purported workspace manifest is at least two levels up from the project manifest, or is located in the user's home directory, produce an additional help message which speculates that the workspace manifest may be extraneous and should then be either deleted or relocated to avoid nesting unrelated projects.

Notes

@rustbot label +A-diagnostics +A-workspaces +E-easy

@kpreid kpreid 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 May 11, 2024
@rustbot rustbot added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-workspaces Area: workspaces E-easy Experience: Easy labels May 11, 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-workspaces Area: workspaces C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants