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

std::error::Error is not implemented for eyre::Report<color_eyre::Handler> #30

Closed
vitorenesduarte opened this issue Jun 22, 2020 · 5 comments

Comments

@vitorenesduarte
Copy link

Hi. After updating eyre from 0.4.3 to 0.5.0 and color-eyre from 0.3.4 to 0.4.1 I'm getting

the trait `std::error::Error` is not implemented for `eyre::Report<color_eyre::Handler>`

when using the ? operator. I'm not sure if this is a bug or the breaking change implied the version bump. Thanks.

@yaahc
Copy link
Collaborator

yaahc commented Jun 22, 2020

I'm sorry to say but it is impossible to implement std::error::Error for eyre::Report<H> or any similar type. You'll likewise find that std::error::Error is not implemented for anyhow::Error or Box<dyn Error>. This is because you cannot implement both From<E: Error> and Error. All types already implement From<T> for T which does a no-op conversion, if eyre::Report implemented Error the compiler wouldn't know whether or not it should wrap itself in another Report or do nothing each time you try to convert a report into a report.

The breaking change was related to a type inference bug in the eyre! macro, can you show me the exact code sample you have that is producing this error? If you have code that did compile that no longer compiles it probably indicates that the macro was erroneously compiling the code before but I just want to be sure.

@vitorenesduarte
Copy link
Author

Thanks for explaining. The last commit in this branch bumps eyre, leading to the error above, for example in this line: https://github.com/vitorenesduarte/fantoch/blob/eyre_bump/fantoch_exp/src/ping.rs#L60

(not sure if it helps, but in a few minutes the error should also be visible here in the "Check fantoch_exp" step)

@yaahc
Copy link
Collaborator

yaahc commented Jun 22, 2020

aaah, this is because you upgraded before tsunami did, so it sees the two Reports as different types which means it doesn't apply the From<T> for T conversion and instead tries to resolve the conversion via the only other From impl, which is From<E: Error>.

It's probably worth waiting on this one, the breaking change that was made was exceedingly minor and I'm now kinda regretting even making it, but I'm also planning a much bigger breaking change in the near future with this PR #29. Short term I recommend just sticking with the older version, but if you need to deal with version mismatches now or in the future one work around is to first convert the Report into a Box<dyn Error> and then convert that back into the new report type, this sadly discards the context of the original report so I'm not even sure its worth it but it will at least preserve the full chain of errors and gather context where it is converted which might be sufficient.

https://docs.rs/eyre/0.5.0/eyre/struct.Report.html#impl-From%3CReport%3CH%3E%3E

@vitorenesduarte
Copy link
Author

Ah, I see. Thanks for pointing it out. I'll wait for that PR then. Thanks.

@blueforesticarus
Copy link

blueforesticarus commented Jun 2, 2023

I always end up hitting this whenever I have a trait with an associated Error type.

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

No branches or pull requests

3 participants