#retry #tor #arti #async #record

retry-error

An error type for an operation that can fail more than once

17 releases

0.5.2 Apr 2, 2024
0.5.1 Sep 5, 2023
0.5.0 Aug 1, 2023
0.4.2 Jun 30, 2023
0.0.0 Jun 24, 2021

#455 in Rust patterns

Download history 267/week @ 2023-12-22 155/week @ 2023-12-29 318/week @ 2024-01-05 424/week @ 2024-01-12 387/week @ 2024-01-19 183/week @ 2024-01-26 240/week @ 2024-02-02 314/week @ 2024-02-09 213/week @ 2024-02-16 346/week @ 2024-02-23 2079/week @ 2024-03-01 543/week @ 2024-03-08 918/week @ 2024-03-15 1861/week @ 2024-03-22 1102/week @ 2024-03-29 1135/week @ 2024-04-05

5,046 downloads per month
Used in 41 crates (5 directly)

MIT/Apache

17KB
300 lines

retry-error

An error attempt to represent multiple failures.

This crate implements RetryError, a type to use when you retry something a few times, and all those attempts can fail differently each time. Instead of returning only a single error, it records all of the errors received, in case they are different.

This crate is developed as part of Arti, a project to implement Tor in Rust. It's used by higher-level crates that retry operations.

Example

use retry_error::RetryError;

fn some_operation() -> anyhow::Result<bool> {
   unimplemented!(); // example
}

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),
       }
   }
   // All attempts failed; return all the errors.
   return Err(err);
}

License: MIT OR Apache-2.0

No runtime deps