Replies: 1 comment 1 reply
-
Oh, that's an interesting problem. A slightly reduced case: use snafu::prelude::*;
fn main() -> Result<(), Error> {
std::fs::read_to_string("").whatever_context("test")?;
Ok(())
}
#[derive(Debug, Snafu)]
pub(crate) enum Error {
#[snafu(context(false), display("{source}"))]
Other { source: OtherError },
#[snafu(whatever, display("{message}"))]
Whatever {
message: String,
#[snafu(source(from(Box<dyn std::error::Error + Send + Sync>, Some)))]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
}
#[derive(Debug, Snafu)]
struct OtherError; Let's check out the signature: fn whatever_context<S, E2>(self, context: S) -> Result<T, E2>
where
S: Into<String>,
E2: FromString,
E: Into<E2::Source>,
There's also the I think the key thing that's happening here is:
Indeed, adding impl ::core::convert::From<OtherError> for Error If we replace the match std::fs::read_to_string("").whatever_context("test") {
Ok(v) => v,
Err(e) => return Err(e),
}; I guess that indicates one solution — you could create your own Sorry for missing this post for so long! |
Beta Was this translation helpful? Give feedback.
-
I'm migrating away from using mostly whatever type errors, to more structured errors. One error uses
#[context(false)]
to simplify passing a Snafu error from a child module, like:But it gives the error:
Is there an alternative to eliminating all whatever_context calls, or typehinting them?
Beta Was this translation helpful? Give feedback.
All reactions