error-stack: Overhaul of the "related-errors" feature #2377
Replies: 3 comments 23 replies
-
As a big proponent of related errors (after all, I was the one that first implemented them 😅), I'd like to give some context and my view/opinion on the matter. I agree with @TimDiekmann that the potential for related errors is significant but may have untapped potential, but I am not in favor of any of the outlined proposals.
I think this is by far the greatest issue, then again we have solved this through the
Yes, but I don't think that this is a problem of related errors, more like that the API is currently in between pre and post related errors.
This is still from the
I think this is generally just a thing that happens with nested values, same applies to things like
This is something I am painfully aware of, but something that I at least locally have several fixes for. By implementing Both solutions outlined are lacking because, IMO they either break encapsulation or hinder functionality (a lot). They only allow us to attach multiple contexts, but not create a real tree of reports, with independent attachments, but in a real-world application whenever there are independent computations, we'd like to aggregate we take multiple reports and smoosh them together. This means that we have two completely independent reports that are added together. This can happen multiple times, building up a report meaning that these multiple contexts might be deep down in the tree. Now I need to know/test if there have been multiple reports instead of a single API call. These would practically reduce the functionality to the one present in miette, the error-handling library I "escaped" from, because of these exact reasons D: In my opinion, it would make more sense to go more in the tree direction, instead of trying to fit a tree-sized piece in a stack-shaped hole. I think that the biggest problems for related errors in error-stack are:
Do I have a specific solution in mind right now? Partially. I think for (1) we can already do a lot more with methods exposed for iterators and tuples ( |
Beta Was this translation helpful? Give feedback.
-
Moving this up so that our discussion can stay focused
Separation between
|
Beta Was this translation helpful? Give feedback.
-
Done in #5047 |
Beta Was this translation helpful? Give feedback.
-
error-stack
has the concept of "related-errors". This means it's possible to have multiple frames living next to each other. The current approach, however, has some downsides:Report
intoError
as there may be multiple sources of an error, which theError
trait does not support. This is especially annoying if libraries want to useerror-stack
but downstream crates don't (for whatever reason) asReport
cannot implementError
.Report::current_context
only returns the first context, not a list of contexts, if multiple contexts at the same level exist. (The current implementation contains a bug in addition insofar that if adding a context and an attachment with the same type the attachment may be returned instead)Report::frames
and similar functions return a linearized iterator of all frames in the order in which they would be printed, however, there is no real distinction between a related error and a non-related errorsource
in favor ofsources
). In most use cases, however, there are no related errors.FromIterator
cannot be implemented onReport
."related-errors" are a great feature and have great potential when processing inside of a loop happens, but in all other cases, it's more of an annoyance.
I was thinking a lot about how to fix the above errors. Generally, I came up with two potential solutions. Both ideas revert most of the API changes done in #747 but all above points should be resolved. However, as we really want to continue supporting "related-errors", I propose to
Report<Vec<C>>
. Methods, currently returning potentially multiple things (likesources
) would only returnT
inReport<T>
(eitherC: Context
orVec<C: Context>
). Sadly, this is not as simple as it sounds. Currently, we rely onC: Context
inReport<C>
, withReport<Vec<C>>
this is not the case anymore. We eventually want to remove theContext
trait as soon ascore::error::Error
has been stabilized, so it's not possible to implementContext
forVec<C: Context>
. As an alternative, aMultiContext
struct could be provided with built-in support fromerror-stack
.FrameKind
enumeration withFrameKind::MultiContext
to hold not only one but multiple contexts.In both cases, we could provide easy conversions from
Vec<Report<C>>
to build a multi-context.Both proposals are breaking changes.
Thanks to @indietyp for maintaining a list or expected changes
Beta Was this translation helpful? Give feedback.
All reactions