pub enum TlqError {
Connection(String),
Timeout(u64),
Server {
status: u16,
message: String,
},
Validation(String),
Serialization(Error),
Io(Error),
MaxRetriesExceeded {
max_retries: u32,
},
MessageTooLarge {
size: usize,
},
}Expand description
Comprehensive error type for TLQ client operations.
This enum covers all possible error conditions that can occur when interacting
with a TLQ server, including network issues, server errors, validation failures,
and client-side problems. Errors are classified as either retryable or non-retryable
using the is_retryable method.
§Error Categories
Retryable errors (transient issues that may succeed on retry):
Connection- Network connectivity problemsTimeout- Request timeoutsIo- I/O errors from the underlying transport
Non-retryable errors (permanent failures that won’t succeed on retry):
Server- HTTP 4xx/5xx responses from the serverValidation- Invalid request parametersSerialization- JSON parsing errorsMaxRetriesExceeded- Retry limit reachedMessageTooLarge- Message exceeds size limit
§Examples
use tlq_client::{TlqClient, TlqError};
#[tokio::main]
async fn main() {
let client = TlqClient::new("localhost", 1337).unwrap();
match client.add_message("test").await {
Ok(message) => println!("Success: {}", message.id),
Err(TlqError::MessageTooLarge { size }) => {
println!("Message too large: {} bytes", size);
},
Err(TlqError::Connection(msg)) => {
println!("Connection failed: {}", msg);
},
Err(e) => println!("Other error: {}", e),
}
}Variants§
Connection(String)
Network connection error
Indicates problems connecting to the TLQ server, such as connection refused, network unreachable, or DNS resolution failures.
Timeout(u64)
Request timeout error
The operation exceeded the configured timeout period. The timeout duration is specified in milliseconds.
Server
HTTP server error response
The TLQ server returned an HTTP error status code (4xx or 5xx). Includes both the status code and any error message from the server.
Validation(String)
Request validation error
Invalid parameters were provided to a client method, such as empty message ID arrays or zero message counts.
Serialization(Error)
JSON serialization/deserialization error
Failed to parse JSON responses from the server or serialize request data to JSON.
Io(Error)
I/O error from underlying transport
Low-level I/O errors from TCP socket operations, such as connection reset, broken pipe, or permission denied.
MaxRetriesExceeded
Maximum retry attempts exceeded
The operation was retried the maximum number of times but still failed.
The retry count is configurable via ConfigBuilder.
MessageTooLarge
Message size exceeds the 64KB limit
TLQ enforces a maximum message size of 65,536 bytes (64KB). Messages larger than this limit are rejected.
Implementations§
Source§impl TlqError
impl TlqError
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Determines if this error type is retryable.
Returns true for transient errors that may succeed if retried:
ConnectionerrorsTimeouterrorsIoerrors
Returns false for permanent errors that won’t succeed on retry:
Servererrors (4xx/5xx HTTP responses)ValidationerrorsSerializationerrorsMaxRetriesExceedederrorsMessageTooLargeerrors
This method is used internally by the retry mechanism to determine whether to attempt retrying a failed operation.
§Examples
use tlq_client::TlqError;
let timeout_error = TlqError::Timeout(5000);
assert!(timeout_error.is_retryable());
let validation_error = TlqError::Validation("Invalid input".to_string());
assert!(!validation_error.is_retryable());