-
Notifications
You must be signed in to change notification settings - Fork 111
Support 'compound errors' #1
Comments
Just linking this here: https://www.reddit.com/r/rust/comments/4xryih/hey_rustaceans_got_an_easy_question_ask_here/d6r0j2u/ In this case, "Some environmental variables not set!" would be the primary error, and a |
I ended up building something like this for a config file parser that I wanted to get as many errors as possible from for similar reasons to @golddranks, i.e. minimize the number of round trips a user with invalid input has to make to fix everything. In my case the error is wholly defined by the sub-errors, since any one of them would be an adequate justification for failure. |
Java added a concept of "suppressed" exceptions that are attached to a "parent" exception for this kind of use case in 1.7: https://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html#addSuppressed(java.lang.Throwable). |
yeah, i’d like something like that too, see #137 for my use case |
As far as the API for this goes, I wonder if it could be something like the The |
Btw. I was bitten by this today again. I keep noticing that I need "combined" errors the most when I'm doing something user-faced. Let's say that there's 5 independent things we could do, and they could independently fail. Computationally it's of course the best to fail fast, but I think it's good UI design to try them all even if one would fail, and then report all the errors, so the user get's a better picture of all the things that need fixing, instead of fixing and error and finding another. I wonder if there would be some use to an "error accumulator API". It could "absorb" multiple |
I'd love to see a push towards a solution of this, maybe as a part of the Libz Bliz effort? Or is that more about evaluation? |
If you want to try a PR/suggest how to do it, feel free! |
I'll see if I can manage to have the time to do that during the next week. No hard promises! |
I see what you mean ;) |
FWIW, I recently had to implement this for a project of mine. I ended up with |
…enabled Fix tests for cache backtrace enabled
Right now error-chain expects errors to be a linear sequence of errors, but twice recently I've encountered situations where I had two errors at the same time and had to figure out something to do with them. In practice one could likely have been considered the cause and the other fallout from the original error, but this relationship wasn't reflected in their structure.
Examples:
It would be good to have a standard way to handle these situations. I imagine a
CompoundError(primary, secondary)
variant that stashes the lesser error withsecondary
perhaps being aVec
.The text was updated successfully, but these errors were encountered: