aws_config/
retry.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

//! Retry configuration

// Re-export from aws-smithy-types
pub use aws_smithy_types::retry::ErrorKind;
pub use aws_smithy_types::retry::ProvideErrorKind;
pub use aws_smithy_types::retry::RetryConfig;
pub use aws_smithy_types::retry::RetryConfigBuilder;
pub use aws_smithy_types::retry::RetryKind;
pub use aws_smithy_types::retry::RetryMode;

/// Errors for retry configuration
pub mod error {
    use std::fmt;
    use std::num::ParseIntError;

    // Re-export from aws-smithy-types
    pub use aws_smithy_types::retry::RetryModeParseError;

    #[derive(Debug)]
    pub(crate) enum RetryConfigErrorKind {
        /// The configured retry mode wasn't recognized.
        InvalidRetryMode {
            /// Cause of the error.
            source: RetryModeParseError,
        },
        /// Max attempts must be greater than zero.
        MaxAttemptsMustNotBeZero,
        /// The max attempts value couldn't be parsed to an integer.
        FailedToParseMaxAttempts {
            /// Cause of the error.
            source: ParseIntError,
        },
    }

    /// Failure to parse retry config from profile file or environment variable.
    #[derive(Debug)]
    pub struct RetryConfigError {
        pub(crate) kind: RetryConfigErrorKind,
    }

    impl fmt::Display for RetryConfigError {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            use RetryConfigErrorKind::*;
            match &self.kind {
                InvalidRetryMode { .. } => {
                    write!(f, "invalid retry configuration")
                }
                MaxAttemptsMustNotBeZero { .. } => {
                    write!(f, "invalid configuration: It is invalid to set max attempts to 0. Unset it or set it to an integer greater than or equal to one.")
                }
                FailedToParseMaxAttempts { .. } => {
                    write!(f, "failed to parse max attempts",)
                }
            }
        }
    }

    impl std::error::Error for RetryConfigError {
        fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
            use RetryConfigErrorKind::*;
            match &self.kind {
                InvalidRetryMode { source, .. } => Some(source),
                FailedToParseMaxAttempts { source, .. } => Some(source),
                MaxAttemptsMustNotBeZero { .. } => None,
            }
        }
    }

    impl From<RetryConfigErrorKind> for RetryConfigError {
        fn from(kind: RetryConfigErrorKind) -> Self {
            Self { kind }
        }
    }
}