kafka_backup_core/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Configuration error: {0}")]
13 Config(String),
14
15 #[error("Kafka error: {0}")]
17 Kafka(#[from] KafkaError),
18
19 #[error("Storage error: {0}")]
21 Storage(#[from] StorageError),
22
23 #[error("Compression error: {0}")]
25 Compression(String),
26
27 #[error("Serialization error: {0}")]
29 Serialization(String),
30
31 #[error("IO error: {0}")]
33 Io(#[from] std::io::Error),
34
35 #[error("Manifest error: {0}")]
37 Manifest(String),
38
39 #[error("Topic not found: {0}")]
41 TopicNotFound(String),
42
43 #[error("Backup not found: {0}")]
45 BackupNotFound(String),
46
47 #[error("Connection error: {0}")]
49 Connection(String),
50
51 #[error("Authentication error: {0}")]
53 Authentication(String),
54}
55
56#[derive(Error, Debug)]
58#[non_exhaustive]
59pub enum KafkaError {
60 #[error("Failed to connect to broker {broker}: {message}")]
62 ConnectionFailed { broker: String, message: String },
63
64 #[error("Protocol error: {0}")]
66 Protocol(String),
67
68 #[error("Broker returned error code {code}: {message}")]
70 BrokerError { code: i16, message: String },
71
72 #[error("Operation timed out: {0}")]
74 Timeout(String),
75
76 #[error("No available brokers")]
78 NoBrokersAvailable,
79
80 #[error("Topic does not exist: {0}")]
82 TopicNotExists(String),
83
84 #[error("Partition {partition} not available for topic {topic}")]
86 PartitionNotAvailable { topic: String, partition: i32 },
87
88 #[error("TLS configuration error: {0}")]
90 TlsConfig(String),
91
92 #[error("Failed to load certificate from {path}: {message}")]
94 CertificateLoad { path: String, message: String },
95
96 #[error("Failed to load private key from {path}: {message}")]
98 PrivateKeyLoad { path: String, message: String },
99}
100
101#[derive(Error, Debug)]
103pub enum StorageError {
104 #[error("Object not found: {0}")]
106 NotFound(String),
107
108 #[error("Permission denied: {0}")]
110 PermissionDenied(String),
111
112 #[error("Backend error: {0}")]
114 Backend(String),
115
116 #[error("Invalid path: {0}")]
118 InvalidPath(String),
119}
120
121impl From<serde_json::Error> for Error {
122 fn from(err: serde_json::Error) -> Self {
123 Error::Serialization(err.to_string())
124 }
125}
126
127impl From<serde_yaml::Error> for Error {
128 fn from(err: serde_yaml::Error) -> Self {
129 Error::Serialization(err.to_string())
130 }
131}
132
133impl From<sqlx::Error> for Error {
134 fn from(err: sqlx::Error) -> Self {
135 Error::Storage(StorageError::Backend(err.to_string()))
136 }
137}