Skip to main content

rs_sqs_receiver/
errors.rs

1use std::str::FromStr;
2
3use thiserror::Error;
4
5/// Error types for AWS SQS receiver operations.
6///
7/// This enum represents all possible errors that can occur during
8/// SQS message receiving and processing operations.
9#[derive(Debug, Error)]
10pub enum AwsSqsReceiverError {
11    /// Error that occurs during AWS SQS client initialization.
12    ///
13    /// This error typically happens when there are issues with AWS credentials,
14    /// region configuration, or network connectivity during client setup.
15    #[error("failed to initialize AWS SQS client: {0}")]
16    InitializationError(String),
17
18    #[error("{0}")]
19    GenericError(#[from] GenericError),
20}
21
22/// Generic error type for handling unexpected errors.
23#[derive(Debug, Error)]
24pub struct GenericError(String);
25
26impl GenericError {
27    /// Creates a new `GenericError` with the provided message.
28    pub fn new(message: String) -> Self {
29        GenericError(message)
30    }
31}
32
33impl std::fmt::Display for GenericError {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        write!(f, "{}", self.0)
36    }
37}
38
39impl FromStr for GenericError {
40    type Err = String;
41
42    fn from_str(s: &str) -> Result<Self, Self::Err> {
43        Ok(GenericError::new(s.to_string()))
44    }
45}
46
47impl From<String> for GenericError {
48    fn from(s: String) -> Self {
49        GenericError::new(s)
50    }
51}