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
Can no longer have a backtrace field when using source(from) where the original type is not an error (breaking change in 0.7.2) #364
Comments
Repromain.rs use snafu::prelude::*;
#[derive(Debug, Snafu)]
enum Error {
Variant1 {
#[snafu(source(from(String, Into::into)))]
source: Box<dyn std::error::Error + Send + Sync>,
},
}
fn return_error() -> Result<(), String> {
Err("nope!".to_string())
}
fn demo() -> Result<(), Error> {
return_error().context(Variant1Snafu)
}
fn main() {} Cargo.toml [dependencies]
snafu = "=0.7.1"
snafu-derive = "=0.7.1" OutputUpgrading
|
This occurs if you have
This isn't the error I produced — can you please create a fully contained reproduction? |
Sorry for not sharing it sooner. This is the message below, built against 0.7.2 of both
This is partially my enum: #[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("Unable to build an HDD: {source}"))]
HddBuild {
backtrace: Option<Backtrace>,
#[snafu(source(from(String, Into::into)))]
source: Box<dyn StdError + Send + Sync>,
},
} |
Complete example use snafu::{prelude::*, Backtrace};
#[derive(Debug, Snafu)]
pub struct HddBuildError {
backtrace: Option<Backtrace>,
#[snafu(source(from(String, Into::into)))]
source: Box<dyn std::error::Error + Send + Sync>,
}
fn return_error() -> Result<(), String> {
Err("nope!".to_string())
}
fn demo() -> Result<(), HddBuildError> {
return_error().context(HddBuildSnafu)
}
fn main() {} |
I'll need to dig into the code, but I'm hoping that the fix here is to call the |
Yeah, we generate this: fn into_error(self, error: Self::Source) -> HddBuildError {
HddBuildError {
backtrace: {
use ::snafu::AsErrorSource;
let error = error.as_error_source();
::snafu::GenerateImplicitData::generate_with_source(error)
},
source: (Into::into)(error),
}
} Should need to move the |
Great sleuthing! Thanks for jumping on this one so quickly. 🕵️ |
I want to clean up the commit, but can you try #366 locally and see if that works for your original case? |
Previously, we only converted the source in the source field initializer. However, `GenerateImplicitData::generate_with_source` also needs access to the post-converted value. Fixes #364
Sorry for the delay. #366 works! Thank you. |
Released in 0.7.3 |
I had an error roughly defined as such:
In 0.7.1 this was acceptable. In 0.7.2, it is now saying that
String
does not implementstd::error::Error
which is a requirement forAsErrorSource
. I believe the derive macro is somehow using the from type as the binding for the context, which would be equivalent to trying to have asource: String
field directly, which I know has never worked.The text was updated successfully, but these errors were encountered: