Feature request / discuss: allow errors to have multiple causes
- Dominant language
- Rust
- Stars
- 6.7k
- Forks
- 224
- PR merge metrics
- No merged PRs in 30d
Description
I've run into multiple situations now where X can only succeed if A, B, and C all succeed, but executing each of A/B/C happens independently, so I'd like to be able to do something like the below example.
Using contexts doesn't really make sense here, because A/B/C failing are all independent of each other, they don't cause one another, and contexts are meant to be used for "error 1 happened because of error 2"
Have you ever considered doing this? Do you know anyone who's made a crate like this? This doesn't appear to be something that anyhow/thiserror/snafu support, but it feels like something that could reasonably fit into anyhow.
```
// this is pseudo-code, meant to illustrate the _sentiment_ of what i want, not the actual API
fn x() -> anyhow::Result<()> {
let mut errs = vec![];
match a() {
Ok(_) => ...,
Err(e) => { errs.push(e); },
}
match b() {
Ok(_) => ...,
Err(e) => { errs.push(e); },
}
match c() {
Ok(_) => ...,
Err(e) => { errs.push(e); },
}
if errs.empty() {
Ok(())
} else {
Err(anyhow::Error::sum(errs))
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing anyhow's existing Error and context APIs, then compare how anyhow, thiserror, and snafu represent related errors. The issue does not name files or tests; done would require a settled API and behavior for collecting and reporting independent causes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100