-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Proof of concept of dyn dispatch based report handler #97
Conversation
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.
This looks great -- I am optimistic about the approach. I think I wouldn't want to land this in anyhow
right away but I would be on board with accepting something like this after iterating on the specific signatures in a separate crate and having some built out ecosystem of those handlers to ensure we've covered the use cases that this is intended to cover.
On the |
That sounds like a great approach |
Sounds reasonable. I'm in the process of applying this change to Once I'm done making the changes in |
This has been in |
Because there's not currently an API for capturing the disabled backtrace I'm going to go ahead and add a required fn on the fn backtrace(&self, error: &(dyn StdError + 'static)) -> &crate::backtrace::Backtrace; That way any customizers will just have to implement this properly or explicitly panic if they don't want to support backtraces, then in the future we can change this to a default trait fn that returns a reference to a statically captured disabled backtrace if the source error didn't capture one. |
Sounds good to me. Could you make sure to publish release notes or a changelog for eyre, including retroactively for the past couple releases if possible? I noticed there have been a couple breaking changes quite recently and couldn't find a writeup of what changed, which would help me evaluate how baked this is. Separately, from skimming crates.io it looks like the majority of the downstream crates not written by you are using old versions of eyre i.e. without this implementation; ideally we'd make sure they are able to upgrade and are happy with the new design. |
Sure! I can tell you now what the recent breaking changes are. The most recent one was removing the generic parameter in favor of the trait object approach. The one before that was to fix a bug in the |
I've had a couple of upgrade reports, the biggest issue so far has been people forgetting to add the |
@@ -584,15 +588,142 @@ pub trait Context<T, E>: context::private::Sealed { | |||
F: FnOnce() -> C; | |||
} | |||
|
|||
static HOOK: OnceCell<ErrorHook> = OnceCell::new(); |
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.
lmk if you want me to move this all to a handler.rs
file or something
} | ||
|
||
#[cfg(not(feature = "std"))] | ||
trait ReportHandler: core::any::Any + Send + Sync { |
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.
I couldn't find a better way to make this trait conditionally pub, we can't export this trait under no_std
because the StdError
trait is private but we still need to use this trait to format the error reports via the DefaultHandler when in no_std
.
} | ||
} | ||
|
||
#[cfg(feature = "std")] |
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.
I think we might want to add some doc_cfg's for all these publicly exported std
only apis.
|
||
impl crate::ReportHandler for crate::DefaultHandler { | ||
#[cfg(backtrace)] | ||
fn backtrace<'a>( |
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.
I'm not sure we can have a publicly exported method that depends on a non feature cfg
, I'll make sure to test this when I port color-eyre
to depend on this branch
https://github.com/yaahc/color-anyhow/actions/runs/174054634 seems to be working ^_^ Edit: JK, it doesn't work for the |
I've run into another snag with implenting backtrace support in Here's the problem though... Apparently you can't do optional deps based on I can work around this by copying the |
Well, with sufficient application of https://github.com/yaahc/color-anyhow/actions/runs/174105901 |
@mystor raised some pretty good concerns about the |
Regarding the earlier question about how "Baked" the design is. One area where I don't think its fully baked yet is how it interacts with My worry is that if it isn't possible to just pass the location all the way into the custom handler via My existing ideas for working around the issue (if it indeed ends up being an issue) include either:
|
add a Backtrace::disabled function Based upon @dtolnay's suggestion here: dtolnay/anyhow#97 (comment)
Status updateI've had More details can be found here eyre-rs/eyre#35 (comment) All in all I'm confident in the current design and would like to move forward with finalizing this PR, getting it up to date and consistent with Ecosystem CompatibilityThat said, I do have one extra goal that I want to aim for. Ideally, I'd like custom hook libraries like |
Status is more or less that we need to resolve the following blockers:
|
Is this still possible? |
Bump - now 2024 and people on Primeagens stream are making fun of the fact we have multiple error libraries. |
I met with 3 eyre maintainers on June 20 and agreed not to take this approach, with suggestions for a different way to improve interop which they are pursuing. |
No description provided.