Reputation: 6685
I use thiserror crate for error handling inside my project.
I declare an error like this
#[derive(Debug, thiserror::Error)]
enum CustomErrors {
#[error("This is custom error one")]
CustomErrorOne,
#[error("This is custom error two")]
CustomErrorTwo
}
I use this custom error like this
// cut
match foo() {
Err(errors) -> match errors {
CustomErrors::CustomErrorOne => ..., // I want to get access to "This is custom error one" error message here
CustomErrors::CustomErrorTwo => ..., // ...and here
}
}
//cut
Am I understanding correctly that this is not possible due to the philosophy of the thiserror
? And it requires creating a new error message?
Thiserror deliberately does not appear in your public API. (c) Documentation
Upvotes: 4
Views: 2101