-
Notifications
You must be signed in to change notification settings - Fork 61
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
Creating a whatever
error value
#387
Comments
I'm afraid that that would be the best you can do if you want to use #[derive(Debug, Snafu)]
enum Error {
#[snafu(whatever, display("{message}"))]
Generic {
message: String,
#[snafu(source(from(Box<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
},
} You can then use the selector
This supports the various integrations with whatever errors, including the |
@Enet4 maybe one more question, |
As far as I know, that is not whatever-specific. Any error type or variant may have a dynamic source error. #[derive(Debug, Snafu)]
enum Error {
#[snafu(whatever, display("{message}"))]
Generic {
message: String,
#[snafu(source(from(Box<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
},
#[snafu(display("Failed with code {code}: {message}"))]
WithCode {
message: String,
code: i32,
#[snafu(source(from(Box<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
},
} |
I can't think of any technical reason that Then that would be Whatever::from("msg") |
yes, this is exactly what I did, and I also have to have something like this in place. For some reason I have some typing hell making it work for all the cases. Will give it another try. |
That could bring some issues. Snafu should take care of converting the source for you. Too many calls to |
Since I also have Option: #[snafu(display("provider error while accessing `{}`: `{}`", path, msg))]
ProviderSourceError {
path: String,
msg: String,
#[snafu(source(from(Box<dyn std::error::Error + Send + Sync>, Some)))]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
}, I'm getting lots of incompatibilities. I guess |
So far the proper shorthand for creating the value (but not returning immediately) was something along:
is there a shorter, nicer way?
The text was updated successfully, but these errors were encountered: