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

Don't panic from WorkspaceDefaultMembers? #254

Open
sourcefrog opened this issue Nov 8, 2023 · 5 comments
Open

Don't panic from WorkspaceDefaultMembers? #254

sourcefrog opened this issue Nov 8, 2023 · 5 comments

Comments

@sourcefrog
Copy link

Hi, https://docs.rs/cargo_metadata/0.18.1/cargo_metadata/struct.WorkspaceDefaultMembers.html documents that it will panic on cargo <1.70, and it does.

For cargo-mutants, I'd like to use this but also support older versions of cargo, so it would be really nice if this was a runtime error rather than a panic. Or at least, if there was a documented version field that I could check before looking at it. Possibly I am missing some subtlety about why that's not feasible.

Thanks for a really helpful crate.

@jplatte
Copy link

jplatte commented Nov 8, 2023

As a workaround, you can use std::panic::catch_unwind to resume operation in case of a panic (unless you're compiling without unwinding).

@oli-obk
Copy link
Owner

oli-obk commented Nov 8, 2023

You can use the https://crates.io/crates/rustc_version crate to check whether your rust is new enough for this field

@sourcefrog
Copy link
Author

Also, just to confirm, this hinges on the version of cargo that's being invoked as cargo metadata, not on the version used to build the program, right?

@oli-obk
Copy link
Owner

oli-obk commented Nov 8, 2023

yes

@clechasseur
Copy link

I ran into this issue also. Would it be acceptable to add a method to the WorkspaceDefaultMembers type to be able to check if it's available or not? If so, I can volunteer to work on a PR for this.

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

4 participants