-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
lib usage: manifest errors with manifest path & source position #6144
Comments
It sounds like it would be quite difficult since the TOML information is discarded immediately after parsing. What kind of API are you interested in? Do you want |
I can see source info is lost in deserialization, though the manifest path would still be very useful. Maybe a method in pub fn manifest_path(&self) -> Option<Path> This means we can highlight a specific workspace manifest rather than the root, or guessing from the message. For deserialise errors this actually gives me everything I need, as I have |
Ok I see now |
The I think the fix here would probably be to annotate some TOML fields that we deserialize with |
Expose manifest error chain in CargoErrors Adds new `ManifestError`s to the `CargoError` causal chain. These errors pass on their display, but provide more detail on which manifests are at fault when failing to build a `Workspace`. This is useful for lib users, in particular rls, allowing lookup of a particular manifest file that caused the error. See #6144. For example a workspace _foo_ where a member _bar_ has an invalid toml manifest would have the error chain: - failed to parse manifest at `/home/alex/project/foo/bar/Cargo.toml` _ManifestError: /home/alex/project/foo/Cargo.toml_ - failed to parse manifest at `/home/alex/project/foo/bar/Cargo.toml` _ManifestError: /home/alex/project/foo/bar/Cargo.toml_ - failed to parse manifest at `/home/alex/project/foo/bar/Cargo.toml` - could not parse input as TOML - expected a value, found an equals at line 8 This will allow rls to point to a particular workspace member's manifest file when that manifest fails to deserialize, has invalid paths, etc. This change should not affect binary use.
We now have a decent way to pick the workspace member manifest with Though outside of In general, I think it would be better for cargo to have errors with info via methods and have this info built into an error string as late as possible. This would give lib users much more to work with. But as cargo is mostly a cli project I can see why we are where we are. Enriching the new errors with info and adding new ones if necessary is probably the way forward. |
That sounds like a good strategy to me! I'm all for improving Cargo's library experience as well :) |
With RLS dead, is anyone still requesting this or should we close this? |
I've been looking at generating manifest diagnostics from cargo errors in rls (rust-lang/rls#1079). It's not easy to deduce which workspace manifests are affected by the error, or where exactly in the manifest relates.
Would it be possible to include somewhere in the causal chain:
The latter actually already exists for toml deserialise errors with
toml::de::Error::line_col
, though not the former.For example at the moment in rls the best I can do, without more fragile inference, is assume the root manifest is good enough and highlight all of it.
Here I'd prefer to be highlighting the
version-check = "0.1"
line.The text was updated successfully, but these errors were encountered: