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

CargoMetadata variant on enum Error is not enough structured #168

Open
Stargateur opened this issue Nov 16, 2021 · 4 comments
Open

CargoMetadata variant on enum Error is not enough structured #168

Stargateur opened this issue Nov 16, 2021 · 4 comments

Comments

@Stargateur
Copy link

CargoMetadata {
  stderr: String,
}

CargoMetadata is not usable to give a precise error to the user, notably on program like bacon that end up doing a random parsing on stderr.

@Stargateur Stargateur changed the title CargoMetadata is not enough structured CargoMetadata variant on enum Error is not enough structured Nov 16, 2021
@oli-obk
Copy link
Owner

oli-obk commented Nov 16, 2021

Hmm... the stderr is unstructured, so I'm not sure how we could emit something better. Do you have any suggestions on how to resolve this issue?

@Stargateur
Copy link
Author

Stargateur commented Nov 16, 2021

I don't know much about cargo metadata maybe by doing the parsing trying a "best guess" of the underline error and fallback to a raw error if the parsing didn't guess the error type, doing the parsing here have the big advantage to not implement the parsing in every crate that use cargo_metadata:

enum Error {
    CargoMetadata(CargoMetadataError),
    // ..
}

enum CargoMetadataError {
  ConfigNotFound {
    file: BufPath,
    dir: BufPath,
  },
  OtherError,
  Unknown{
    stderr: String,
  },
}

This is clearly not perfect but I don't have any better since this is just a wrapper other cargo metadata subcommand. But I think most users of this crate will gain a lot to maintains a common parsing of stderr and the fallback allow to be flexible if cargo change the stderr output.

The first thing to have would be to have a list of every current error cargo metadata can produce. The error can implement Display and Error to reverse back to original output making this breaking change painless.

@oli-obk
Copy link
Owner

oli-obk commented Nov 16, 2021

Hmm... I dimly remember that there is a way to make cargo generally emit json errors, maybe that works for cargo metadata, too?

@Stargateur
Copy link
Author

Stargateur commented Nov 17, 2021

you know better than me but I search a little when you ask me a solution and didn't find anything. But I think we could make a request for it #63. And this would help much more than just this crate so that would be very nice. Having a error output format, and have error structure public. To everyone that wrap cargo command. I don't see why cargo is not just a library for everyone could use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants