RetryError

Enum RetryError 

Source
pub enum RetryError {
    MaxAttemptsExceeded {
        attempts: u32,
        max_attempts: u32,
    },
    MaxDurationExceeded {
        duration: Duration,
        max_duration: Duration,
    },
    OperationTimeout {
        duration: Duration,
        timeout: Duration,
    },
    Aborted {
        reason: String,
    },
    ConfigError {
        message: String,
    },
    DelayStrategyError {
        message: String,
    },
    ExecutionError {
        source: Box<dyn Error + Send + Sync>,
    },
    Other {
        message: String,
    },
}
Expand description

Error type for the retry module

Defines various error conditions that can occur during retry operations, including exceeding maximum retries, exceeding duration limits, operation abortion, configuration errors, etc.

§Features

  • Supports unified handling of multiple error types
  • Provides detailed error information and context
  • Supports error chain tracking (via the source method)
  • Implements the standard Error trait for interoperability with other error types

§Use Cases

Suitable for operations requiring retry mechanisms, such as network requests, file operations, database connections, etc. Returns a corresponding RetryError when retry strategies fail or encounter unrecoverable errors.

§Example

use prism3_retry::RetryError;

// Create maximum attempts exceeded error
let error = RetryError::max_attempts_exceeded(5, 3);
println!("Error: {}", error);

// Create execution error
let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found");
let retry_error = RetryError::execution_error(io_error);
println!("Execution error: {}", retry_error);

§Author

Haixing Hu

Variants§

§

MaxAttemptsExceeded

Maximum attempts exceeded

Triggered when the number of retries reaches or exceeds the preset maximum retry count.

§Fields

  • attempts - Actual number of attempts
  • max_attempts - Maximum allowed retry count

Fields

§attempts: u32
§max_attempts: u32
§

MaxDurationExceeded

Maximum duration exceeded

Triggered when the total duration of retry operations exceeds the preset maximum duration.

§Fields

  • duration - Actual time consumed
  • max_duration - Maximum allowed duration

Fields

§duration: Duration
§max_duration: Duration
§

OperationTimeout

Single operation timeout

Triggered when the execution time of a single operation exceeds the configured operation timeout. This differs from MaxDurationExceeded, which is for the total time limit of the entire retry process.

§Fields

  • duration - Actual execution time
  • timeout - Configured timeout duration

Fields

§duration: Duration
§timeout: Duration
§

Aborted

Operation aborted

Triggered when retry operation is aborted by external factors (e.g., user cancellation, system signals).

§Fields

  • reason - Description of the abort reason

Fields

§reason: String
§

ConfigError

Configuration error

Triggered when retry configuration parameters are invalid or conflicting.

§Fields

  • message - Error description message

Fields

§message: String
§

DelayStrategyError

Delay strategy error

Triggered when delay strategy configuration is erroneous or an error occurs while calculating delays.

§Fields

  • message - Error description message

Fields

§message: String
§

ExecutionError

Execution error

Wraps the original error when the retried operation itself fails.

§Fields

  • source - Original error, supports error chain tracking

Fields

§source: Box<dyn Error + Send + Sync>
§

Other

Other errors

Used to represent other error situations that don’t fall into the above categories.

§Fields

  • message - Error description message

Fields

§message: String

Implementations§

Source§

impl RetryError

Source

pub fn max_attempts_exceeded(attempts: u32, max_attempts: u32) -> Self

Create maximum attempts exceeded error

Use this method to create an error when the retry count reaches or exceeds the preset maximum retry count.

§Parameters
  • attempts - Actual number of attempts
  • max_attempts - Maximum allowed retry count
§Returns

Returns a RetryError containing retry count information

§Example
use prism3_retry::RetryError;

let error = RetryError::max_attempts_exceeded(5, 3);
assert!(error.to_string().contains("Maximum attempts exceeded"));
Source

pub fn max_duration_exceeded(duration: Duration, max_duration: Duration) -> Self

Create maximum duration exceeded error

Use this method to create an error when the total duration of retry operations exceeds the preset maximum duration.

§Parameters
  • duration - Actual time consumed
  • max_duration - Maximum allowed duration
§Returns

Returns a RetryError containing time information

§Example
use prism3_retry::RetryError;
use std::time::Duration;

let error = RetryError::max_duration_exceeded(
    Duration::from_secs(10),
    Duration::from_secs(5)
);
assert!(error.to_string().contains("Maximum duration exceeded"));
Source

pub fn operation_timeout(duration: Duration, timeout: Duration) -> Self

Create single operation timeout error

Use this method to create an error when the execution time of a single operation exceeds the configured operation timeout.

§Parameters
  • duration - Actual execution time
  • timeout - Configured timeout duration
§Returns

Returns a RetryError containing time information

§Example
use prism3_retry::RetryError;
use std::time::Duration;

let error = RetryError::operation_timeout(
    Duration::from_secs(10),
    Duration::from_secs(5)
);
assert!(error.to_string().contains("Operation timeout"));
Source

pub fn aborted(reason: &str) -> Self

Create abort error

Use this method to create an error when the retry operation is aborted by external factors.

§Parameters
  • reason - Reason for abortion
§Returns

Returns a RetryError containing the abort reason

§Example
use prism3_retry::RetryError;

let error = RetryError::aborted("User cancelled operation");
assert!(error.to_string().contains("Operation aborted"));
Source

pub fn config_error(message: &str) -> Self

Create configuration error

Use this method to create an error when retry configuration parameters are invalid or conflicting.

§Parameters
  • message - Error description message
§Returns

Returns a RetryError containing error information

§Example
use prism3_retry::RetryError;

let error = RetryError::config_error("Maximum retry count cannot be negative");
assert!(error.to_string().contains("Configuration error"));
Source

pub fn delay_strategy_error(message: &str) -> Self

Create delay strategy error

Use this method to create an error when delay strategy configuration is erroneous or an error occurs while calculating delays.

§Parameters
  • message - Error description message
§Returns

Returns a RetryError containing error information

§Example
use prism3_retry::RetryError;

let error = RetryError::delay_strategy_error("Delay time calculation overflow");
assert!(error.to_string().contains("Delay strategy error"));
Source

pub fn execution_error<E: Error + Send + Sync + 'static>(error: E) -> Self

Create execution error

Use this method to wrap the original error as RetryError when the retried operation itself fails.

§Parameters
  • error - Original error, must implement Error + Send + Sync trait
§Returns

Returns a RetryError wrapping the original error

§Example
use prism3_retry::RetryError;

let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found");
let retry_error = RetryError::execution_error(io_error);
assert!(retry_error.to_string().contains("Execution error"));
Source

pub fn execution_error_box(error: Box<dyn Error + Send + Sync>) -> Self

Create execution error (from Box)

When you already have a Box, use this method to create an execution error directly. This avoids additional boxing operations.

§Parameters
  • error - Boxed error
§Returns

Returns a RetryError wrapping the original error

§Example
use prism3_retry::RetryError;

let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found");
let boxed_error = Box::new(io_error);
let retry_error = RetryError::execution_error_box(boxed_error);
assert!(retry_error.to_string().contains("Execution error"));
Source

pub fn other(message: &str) -> Self

Create other error

Use this method to create an error for other error situations that don’t fall into the above categories.

§Parameters
  • message - Error description message
§Returns

Returns a RetryError containing error information

§Example
use prism3_retry::RetryError;

let error = RetryError::other("Unknown error type");
assert!(error.to_string().contains("Other error"));

Trait Implementations§

Source§

impl Debug for RetryError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RetryError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format error information into a readable string

Provides error descriptions for each error type, including relevant contextual information.

§Parameters
  • f - Formatter
§Returns

Returns formatting result

Source§

impl Error for RetryError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Get the root cause of the error

For ExecutionError type, returns the original error; for other types, returns None. This supports error chain tracking, aiding in debugging and error handling.

§Returns

Returns the root cause of the error, or None if it doesn’t exist

1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Box<dyn Error + Send + Sync>> for RetryError

Convert from boxed error types

Provides automatic conversion from Box<dyn Error + Send + Sync> to RetryError. This allows converting any boxed error directly to RetryError.

§Parameters

  • error - Boxed error

§Returns

Returns a RetryError wrapping the original error

§Example

use prism3_retry::RetryError;

let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found");
let boxed_error: Box<dyn std::error::Error + Send + Sync> = Box::new(io_error);
let retry_error: RetryError = boxed_error.into();
Source§

fn from(error: Box<dyn Error + Send + Sync>) -> Self

Convert boxed error to RetryError

Source§

impl From<Error> for RetryError

Convert from standard error types

Provides automatic conversion from std::io::Error to RetryError. This simplifies error handling, allowing direct use of the ? operator.

§Parameters

  • error - IO error

§Returns

Returns a RetryError wrapping the IO error

§Example

use prism3_retry::{RetryError, RetryResult};

fn io_operation() -> RetryResult<()> {
    let file = std::fs::File::open("nonexistent_file.txt")?;
    // Do something with file
    Ok(())
}
Source§

fn from(error: Error) -> Self

Convert std::io::Error to RetryError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V