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

lib usage: manifest errors with manifest path & source position #6144

Closed
alexheretic opened this issue Oct 6, 2018 · 7 comments
Closed

lib usage: manifest errors with manifest path & source position #6144

alexheretic opened this issue Oct 6, 2018 · 7 comments
Labels
A-cargo-api Area: cargo-the-library API and internal code issues A-diagnostics Area: Error and warning messages generated by Cargo itself. S-propose-close Status: A team member has nominated this for closing, pending further input from the team

Comments

@alexheretic
Copy link
Member

alexheretic commented Oct 6, 2018

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:

  • a manifest path
  • a source position/range

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.

@ehuss
Copy link
Contributor

ehuss commented Oct 6, 2018

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 Error objects with extra fields returned from compile_with_exec?

@alexheretic
Copy link
Member Author

I can see source info is lost in deserialization, though the manifest path would still be very useful.

Maybe a method in CargoError

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 line_col.

@alexheretic
Copy link
Member Author

Ok I see now CargoError is just a failure::Error. But some way of getting the manifest path from compile_with_exec errors is what I'm after.

@alexcrichton
Copy link
Member

The toml crate awhile back got support for Spanned<T> which means we now have the capability to preserve span information beyond deserialization (yay!)

I think the fix here would probably be to annotate some TOML fields that we deserialize with Spanned<T> and then if an error happens when processing that field we've got the span information to resolve to a file/line number

bors added a commit that referenced this issue Oct 13, 2018
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.
@alexheretic
Copy link
Member Author

We now have a decent way to pick the workspace member manifest with ManifestErrors & ResolveErrors, this covers a decent bunch of cases.

Though outside of toml::de::Errors, I'm still highlighting the whole manifest.

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.

@alexcrichton
Copy link
Member

That sounds like a good strategy to me! I'm all for improving Cargo's library experience as well :)

@ehuss ehuss added A-cargo-api Area: cargo-the-library API and internal code issues A-diagnostics Area: Error and warning messages generated by Cargo itself. labels Apr 6, 2020
@epage
Copy link
Contributor

epage commented Oct 10, 2023

With RLS dead, is anyone still requesting this or should we close this?

@epage epage added the S-propose-close Status: A team member has nominated this for closing, pending further input from the team label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-api Area: cargo-the-library API and internal code issues A-diagnostics Area: Error and warning messages generated by Cargo itself. S-propose-close Status: A team member has nominated this for closing, pending further input from the team
Projects
None yet
Development

No branches or pull requests

4 participants