-
Notifications
You must be signed in to change notification settings - Fork 83
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
GEN-68: .into_report()
doesn't include error source chains
#2127
Comments
Hi @jquesada2016 and thanks for filing this issue! I really like the idea, but sadly I don't see how this could be implemented. One way how this could be possible is to not store the source errors in the report but install a
Anyway, this would require installing a debug hook for each error, which you are expecting, which is obviously unviable. Sadly, to my knowledge, it's not possible to use the Provider API to get all objects, which are implementing a certain trait (i.e. It's likely, that this method will require a nightly compiler to work. What do you think? |
The last option you suggested might be the best option out of the ones you proposed. What if
struct IntoReportFrame {
depth: usize,
error: Rc<dyn Error>,
} The advantages to this, is that providing and downcasting would work just fine! We'd just need to check for two types: a) the original The biggest downside to this approach would be performance on errors, since you would need to walk down the error source chain for each level. |
Your approach most likely would work, however, we would need to use The biggest issue, currently, is to detect if the Report is created from an |
If you like, I can give If I understood you correctly, |
Sure, why not! 🎉 Generally, this consists of two parts:
|
Hi @jquesada2016, I was curious about this, and wanted to check in to see if you'd been able to give it any kind of a look. Thanks! |
@nonparibus I have not had a chance to give this a shot, but have not forgotten about it either. |
.into_report()
doesn't include error source chains.into_report()
doesn't include error source chains
Would it be possible to implement this for anyhow at least? Without it, it is very difficult to gradually transition a code base from anyhow to error-stack. You basically end up having to switch everything over at once (or loose backtraces, which is a non-starter). |
Here's the workaround I'm using (requires anyhow and anyhow feature enabled in error_stack) use error_stack::{Context, IntoReportCompat, Report};
/// Converts `Result<Ok, Err>` into `Result<Ok, Report<Err>>`
/// Workaround for <https://github.com/hashintel/hash/issues/4355>
pub trait IntoReport {
/// Type of the [`Ok`] value in the [`Result`]
type Ok;
/// Converts the [`Err`] variant of the [`Result`] to a [`Report`]
fn into_report<C: Context>(self, c: C) -> Result<Self::Ok, Report<C>>;
}
impl<T, E: std::error::Error + Send + Sync + 'static> IntoReport for Result<T, E> {
type Ok = T;
#[track_caller]
fn into_report<C: Context>(self, c: C) -> Result<<Result<T, E> as IntoReport>::Ok, Report<C>> {
IntoReportCompat::into_report(self.map_err(|e| anyhow::anyhow!(e)))
.map_err(|e| e.change_context(c))
}
} |
I implemented capturing for |
Related Problem
The problem I have seen is that when calling
.into_report()
on errors,Report
only includes the top-most error, and does not include any of the sources.Proposed Solution
I propose that
.into_report()
go through the source chain and add each source entry as a printable attachment, (or context frame?) to the error.Alternatives
No response
Additional context
I've run into this problem using the Rust AWS SDK, where
SdkError
results in generic"service error"
messages, where in reality, if we were to follow the error source chain, we would get all the information we'd need to diagnose and fix the error.The text was updated successfully, but these errors were encountered: