2021-06-17 23:41:47 +01:00
|
|
|
# retry-error
|
2021-05-25 20:41:23 +01:00
|
|
|
|
2021-06-17 23:41:47 +01:00
|
|
|
An error attempt to represent multiple failures.
|
2021-05-25 20:41:23 +01:00
|
|
|
|
2021-06-17 23:41:47 +01:00
|
|
|
This crate implements [`RetryError`], a type to use when you
|
|
|
|
retry something a few times, and all those attempts. Instead of
|
2021-05-25 20:41:23 +01:00
|
|
|
returning only a single error, it records _all of the errors
|
2021-06-17 23:41:47 +01:00
|
|
|
received_, in case they are different.
|
2021-05-25 20:41:23 +01:00
|
|
|
|
2021-06-17 23:41:47 +01:00
|
|
|
This crate is developed as part of
|
2021-05-25 20:41:23 +01:00
|
|
|
[Arti](https://gitlab.torproject.org/tpo/core/arti/), a project to
|
|
|
|
implement [Tor](https://www.torproject.org/) in Rust.
|
|
|
|
It's used by higher-level crates that retry
|
|
|
|
operations.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```rust
|
2021-06-17 23:41:47 +01:00
|
|
|
use retry_error::RetryError;
|
2021-05-25 20:41:23 +01:00
|
|
|
|
2021-11-29 14:15:15 +00:00
|
|
|
fn some_operation() -> anyhow::Result<bool> {
|
|
|
|
unimplemented!(); // example
|
2021-11-29 12:25:26 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 14:15:15 +00:00
|
|
|
fn example() -> Result<(), RetryError<anyhow::Error>> {
|
|
|
|
const N_ATTEMPTS: usize = 10;
|
|
|
|
let mut err = RetryError::in_attempt_to("perform an example operation");
|
|
|
|
for _ in 0..N_ATTEMPTS {
|
|
|
|
match some_operation() {
|
|
|
|
Ok(val) => return Ok(()),
|
|
|
|
Err(e) => err.push(e),
|
|
|
|
}
|
2021-05-25 20:41:23 +01:00
|
|
|
}
|
2021-11-29 14:15:15 +00:00
|
|
|
// All attempts failed; return all the errors.
|
|
|
|
return Err(err);
|
2021-05-25 20:41:23 +01:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
License: MIT OR Apache-2.0
|