Skip to main content

rabbitmq_backup_core/
error.rs

1//! Error types for the RabbitMQ backup core library.
2
3use thiserror::Error;
4
5/// Result type alias using the library's Error type.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Main error type for the RabbitMQ backup library.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// AMQP protocol error
12    #[error("AMQP error: {0}")]
13    Amqp(String),
14
15    /// Stream protocol error
16    #[error("Stream protocol error: {0}")]
17    Stream(String),
18
19    /// Management API error
20    #[error("Management API error: {0}")]
21    ManagementApi(String),
22
23    /// Storage error
24    #[error("Storage error: {0}")]
25    Storage(String),
26
27    /// Configuration error
28    #[error("Configuration error: {0}")]
29    Config(String),
30
31    /// Serialization error
32    #[error("Serialization error: {0}")]
33    Serialization(String),
34
35    /// Checkpoint error
36    #[error("Checkpoint error: {0}")]
37    Checkpoint(String),
38
39    /// Compression error
40    #[error("Compression error: {0}")]
41    Compression(String),
42
43    /// IO error
44    #[error("IO error: {0}")]
45    Io(#[from] std::io::Error),
46
47    /// Connection error
48    #[error("Connection error: {0}")]
49    Connection(String),
50
51    /// Authentication error
52    #[error("Authentication error: {0}")]
53    Authentication(String),
54
55    /// Manifest error
56    #[error("Manifest error: {0}")]
57    Manifest(String),
58}
59
60impl From<serde_json::Error> for Error {
61    fn from(err: serde_json::Error) -> Self {
62        Error::Serialization(err.to_string())
63    }
64}
65
66impl From<serde_yaml::Error> for Error {
67    fn from(err: serde_yaml::Error) -> Self {
68        Error::Serialization(err.to_string())
69    }
70}
71
72impl From<sqlx::Error> for Error {
73    fn from(err: sqlx::Error) -> Self {
74        Error::Checkpoint(err.to_string())
75    }
76}