-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Comments
I just tried to reproduce this and didn't get any errors. Could you provide more concrete reproduction steps and use cases that lead to these mistaken workspace manifests so we can better consider how the user gets into these situations so we understand what errors to look at and how to improve them? |
I can't provide concrete steps for the original example, because the user that had that problem didn't tell us how they got there. In general, issues of this type come from users that don't remember what they did, or don't have enough model of Cargo to say what the relevant things they did are. But here is an example sequence of steps which will produce a (different) broken configuration: $ cargo init
Creating binary (application) package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ rm -r src/ # we decided we didn't want this but didn't notice the other file
$ cargo new foo
Creating binary (application) `foo` package
Adding `foo` as member of workspace at `/<...>/project-structure-test`
warning: compiling this new package may not work due to invalid workspace configuration
failed to parse manifest at `/<...>/project-structure-test/Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ # IDK what that warning means so I will ignore it
$ cd foo
$ cargo check
error: failed to parse manifest at `/<...>/project-structure-test/Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present To be clear, this is an unreasonable sequence of things to do all at once. Imagine, in between the parts, a lot of poking around with file managers and/or editors, trying different |
So what you are wanting to see is something like $ cargo check
-error: failed to parse manifest at `/<...>/project-structure-test/Cargo.toml`
+error: Could not parse workspace for ...
+
+Caused by:
+ failed to parse manifest at `/<...>/project-structure-test/Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present |
Experimented with this a bit and not thrilled with the results
Part of the problem is that annotate-snippets reporting is handled very differently than other errors and its less ideal in this situation. We are also wanting to move as many errors to annotate-snippets as possible. |
More like this:
|
Whichever way, that runs into the same problems. More even since we can't add btw that |
I'd enjoy something simple, like:
That moves away from the "workspace manifest" terminology while remaining helpful for more-experienced users. If there is a way to add a
Also, if you do wish to continue using the manifest terminology, linking to the glossary may be neccessary: https://doc.rust-lang.org/cargo/appendix/glossary.html#manifest In any case, if you have any advice for my input, please let me know! I'm looking to contribute more to Cargo and Rust in general. 😄 |
I stumbled across this thread trying to fix the same problem but for a different reason. For some reason, I'd accidentally deleted a character of the 'package' TOML header so it read 'packag'. All fixed now, but I wanted to know why Cargo just blindly accepted Furthermore, why does Cargo just assume it's a virtual workspace just because the [packag]
name = "li"
version = "0.0.2"
edition = "2021"
[dependencies]
bevy = { version = "0.14.0", features = ["dynamic_linking"] }
serde = "1.0.204"
...
opt-level = 3 |
Instead of erroring on unused keys, Cargo warns. This is helpful when we are adding new functionality to
A package must have at least
I can see improving the error if neither is present, rather than falling through to assuming its a virtual workspace. |
@epage Thanks for the info! |
This comment was marked as outdated.
This comment was marked as outdated.
That the error was confused was brought up in rust-lang#13904
This comment was marked as off-topic.
This comment was marked as off-topic.
fix(toml): Improve error on missing package and workspace That the error was confused was brought up in #13904
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 rancargo 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: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:
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.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
The text was updated successfully, but these errors were encountered: