arrow_zerobus_sdk_wrapper/error.rs
1//! Error types for the Zerobus SDK Wrapper
2//!
3//! This module defines all error types used throughout the wrapper,
4//! providing clear, actionable error messages for developers.
5
6use thiserror::Error;
7
8/// Error type for wrapper operations
9///
10/// All errors are descriptive and actionable, providing sufficient
11/// information for developers to diagnose and resolve issues.
12#[derive(Debug, Clone, Error)]
13pub enum ZerobusError {
14 /// Invalid configuration error
15 ///
16 /// Occurs when configuration values are invalid or missing required fields.
17 #[error("Configuration error: {0}")]
18 ConfigurationError(String),
19
20 /// Authentication failure error
21 ///
22 /// Occurs when authentication with Zerobus fails (invalid credentials,
23 /// expired tokens, etc.).
24 #[error("Authentication error: {0}")]
25 AuthenticationError(String),
26
27 /// Network/connection error
28 ///
29 /// Occurs when network connectivity is lost or connection to Zerobus fails.
30 #[error("Connection error: {0}")]
31 ConnectionError(String),
32
33 /// Arrow to Protobuf conversion failure
34 ///
35 /// Occurs when Arrow RecordBatch data cannot be converted to Protobuf format.
36 #[error("Conversion error: {0}")]
37 ConversionError(String),
38
39 /// Data transmission failure
40 ///
41 /// Occurs when data transmission to Zerobus fails.
42 #[error("Transmission error: {0}")]
43 TransmissionError(String),
44
45 /// All retry attempts exhausted
46 ///
47 /// Occurs when all retry attempts for transient failures have been exhausted.
48 #[error("Retry exhausted: {0}")]
49 RetryExhausted(String),
50
51 /// Token refresh failure
52 ///
53 /// Occurs when authentication token refresh fails.
54 #[error("Token refresh error: {0}")]
55 TokenRefreshError(String),
56}
57
58impl ZerobusError {
59 /// Check if the error is retryable
60 ///
61 /// Returns true for transient errors that should be retried:
62 /// - ConnectionError
63 /// - TransmissionError (if transient)
64 pub fn is_retryable(&self) -> bool {
65 matches!(
66 self,
67 ZerobusError::ConnectionError(_) | ZerobusError::TransmissionError(_)
68 )
69 }
70
71 /// Check if the error indicates token expiration
72 ///
73 /// Returns true if the error suggests the authentication token has expired.
74 pub fn is_token_expired(&self) -> bool {
75 matches!(self, ZerobusError::AuthenticationError(_))
76 }
77}