Skip to content
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

Deriving structs with backtrace fails since fn backtrace has been removed from Error #177

Closed
Systemcluster opened this issue Aug 4, 2022 · 4 comments · Fixed by #182
Closed

Comments

@Systemcluster
Copy link

As of rust-lang/rust#99431 fn backtrace is not part of Error anymore. This causes derives with backtrace to fail; And the following example results in a compilation error.

method `backtrace` is not a member of trait `std::error::Error`
not a member of trait `std::error::Error`
#[derive(Error, Debug)]
#[error("Platform Error {code}")]
pub struct PlatformError {
    backtrace: Backtrace,
    code:      i32,
}
@juntyr

This comment was marked as spam.

@dtolnay
Copy link
Owner

dtolnay commented Aug 11, 2022

This is blocked on rust-lang/rust#100399.

@dtolnay
Copy link
Owner

dtolnay commented Aug 11, 2022

Perhaps not — it looks like anyhow uses BacktraceStatus but thiserror does not.

@Xuanwo
Copy link

Xuanwo commented Aug 12, 2022

Do we need to remove the backtrace method?

let backtrace_method = input.backtrace_field().map(|backtrace_field| {
let backtrace = &backtrace_field.member;
let body = if let Some(source_field) = input.source_field() {
let source = &source_field.member;
let source_backtrace = if type_is_option(source_field.ty) {
quote_spanned! {source.span()=>
self.#source.as_ref().and_then(|source| source.as_dyn_error().backtrace())
}
} else {
quote_spanned! {source.span()=>
self.#source.as_dyn_error().backtrace()
}
};
let combinator = if source == backtrace {
source_backtrace
} else if type_is_option(backtrace_field.ty) {
quote! {
#source_backtrace.or(self.#backtrace.as_ref())
}
} else {
quote! {
std::option::Option::Some(#source_backtrace.unwrap_or(&self.#backtrace))
}
};
quote! {
use thiserror::private::AsDynError;
#combinator
}
} else if type_is_option(backtrace_field.ty) {
quote! {
self.#backtrace.as_ref()
}
} else {
quote! {
std::option::Option::Some(&self.#backtrace)
}
};
quote! {
fn backtrace(&self) -> std::option::Option<&std::backtrace::Backtrace> {
#body
}
}
});

uonr pushed a commit to mythal/boluo-mono that referenced this issue Aug 20, 2022
ariel-miculas added a commit to ariel-miculas/puzzlefs that referenced this issue Nov 15, 2022
Fixes project-machine#47

Unfortunately, deleting the custom Display implementation results in
ugly stacktraces (condensed into one long line instead of pretty
printed) in tests, see 8049c6a for
context. This implementation doesn't work because 'fn backtrace' is not
part of 'Error' anymore.
See: dtolnay/thiserror#177
and dtolnay/anyhow#111

Signed-off-by: Ariel Miculas <amiculas@cisco.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants