-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Derive: specifying invalid struct field type fails with Epic error message #4994
Comments
Worked around it like so (which is a little ugly, but it works) use clap::builder::{PathBufValueParser, TypedValueParser};
fn box_path() -> impl TypedValueParser<Value = Box<Path>> {
PathBufValueParser::new().map(|p| p.into())
}
#[derive(Parser)]
struct Cli {
#[arg(short = 'C', value_parser = box_path())]
foo: Option<Box<Path>>
} |
The derive macro can only see the textual name for a type (ie A subset of that error actually provides some really good hints
though it can't also suggest your workaround. |
#4995 adds support for some serde types |
As part of the message is intentional and our options are limited for resolving this and with us adding support for more types, I'm not seeing what more can be done for this and am closing this. If this needs further discussion, feel free to say something! |
I also hit this error message when implementing |
Please complete the following tasks
Rust Version
1.70
Clap Version
4.3.10
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo check
Actual Behaviour
The user is presented with a truly threatening error message:
Expected Behaviour
The derive macro should produce a human-readable error when it detects an invalid type being used, rather than produce a horrific type error after expansion,
Additionally, it would be nice if parsing into smart pointers was supported. Using a
PathBuf
would be wasteful in my case, as I don't intend on modifying the path, and would like to encode this directly into my type. Using Rc or Arc would also allow cheaply cloning the struct to pass it to other code. Serde allows this afaik.Additional Context
No response
Debug Output
No response
The text was updated successfully, but these errors were encountered: