-
Notifications
You must be signed in to change notification settings - Fork 123
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
Replace fn backtrace()
with Provider
API in Error
derive
#200
Conversation
fn backtrace()
with Provider
APIfn backtrace()
with Provider
API in Error
derive
@JelteF would you be so kind to move requirement from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilslv hmm...regarding the CI failure. I thought it was because of my changes, but I can reproduce the same test failures localy on your last commit in 2022-09-08
nightly Rust. Could you look into it?
.then(|| { | ||
let backtrace_expr = &self.data.members[backtrace]; | ||
quote! { | ||
demand.provide_ref::<std::backtrace::Backtrace>(&#backtrace_expr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Food for thought: One of the reasons for this provider API (afaict) is so more types can be provided that just Backtrace, without needing to add more methods to the Error
trait.
So probably we want to allow this too, e.g. to embed some additionaly context such as trace IDs in there for distributed tracing. This would probabyl be better as a separate PR. I think it makes sense to keep dedicated and easy to use support for the Backtrace
type.
Another idea is to also provide the source
through the provider API, like is done in the rust docs
impl std::error::Error for Error {
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
demand
.provide_ref::<MyBacktrace>(&self.backtrace)
.provide_ref::<dyn std::error::Error + 'static>(&self.source);
}
}
Source: https://doc.rust-lang.org/nightly/std/error/trait.Error.html
Again this would be better in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF I've already raised question of what should be provided and this implementation mirrors thiserror
. As Provider
API is quite new and source()
default impl still returns None
, I think that we shouldn't rush with providing dyn Error
and wait how Provider
API will be used throughout the ecosystem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. but docs need to be updated. Thanks for all the work on this.
@JelteF ping |
Fixes #195 similar to dtolnay/thiserror#182