Comments (11)
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 Results
, and then give back the Ok
s at once, or a combined error object.
from error-chain.
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 Vec
of the individual errors for every environmental variable being the set of the secondary errors.
from error-chain.
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.
from error-chain.
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).
from error-chain.
yeah, iād like something like that too, see #137 for my use case
from error-chain.
As far as the API for this goes, I wonder if it could be something like the Join
struct in the futures
crate?
The error_chain
crate might want to expose a Compound<T>
type, and then opt-in create a Error::Compound
variant for the caller if requested. It does beg the question of what iter()
means at that point: Does it traverse breadth-first or depth-first?
from error-chain.
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?
from error-chain.
If you want to try a PR/suggest how to do it, feel free!
from error-chain.
I'll see if I can manage to have the time to do that during the next week. No hard promises!
from error-chain.
I see what you mean ;)
from error-chain.
FWIW, I recently had to implement this for a project of mine. I ended up with ErrorKind::Multiple
, which had a Vec<Error>
instance as its contents. Iteration was shallow, but Error::flatten(self) -> Error
did a depth-first traversal to create one flat list of errors, with context cloned to each item. This enabled a crate to have an efficient representation for as long as possible, and to then convert to a flat error list immediately before display to a user.
from error-chain.
Related Issues (20)
- If this crate is really drepecate, I should specify it and mark alternatives. HOT 8
- cargo publish error HOT 3
- deprecate quick_main?
- trait objects without an explicit `dyn` are deprecated
- changes to backtrace crate HOT 1
- Shouldn't src/bin/has_backtrace.rs be in examples? HOT 1
- How to implement complex display expression?
- backtrace name collision HOT 1
- use of deprecated try
- minimum version 1.13 for ? operator HOT 1
- How to force documentation when using error_chain HOT 5
- Move Repository To rust-lang
- lint error: use of deprecated item 'std::error::Error::description': use the Display impl or to_string() HOT 2
- Rust 2018 macro export pain HOT 3
- gcc error while testing HOT 3
- Release 0.12.2? HOT 8
- Chaining errors from spawned threads.
- Use feature specific links in error_chain! macro
- Add a feature gate to call DebugBreak on construction
- no rules expected this token in macro call HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from error-chain.