arch_toolkit/
error.rs

1//! Unified error type for arch-toolkit.
2
3use thiserror::Error;
4
5/// Unified error type for all arch-toolkit operations.
6///
7/// This error type covers all possible failure modes across different modules,
8/// providing clear, actionable error messages.
9#[derive(Error, Debug)]
10pub enum ArchToolkitError {
11    /// Network or HTTP request error.
12    #[error("Network error: {0}")]
13    Network(#[from] reqwest::Error),
14
15    /// JSON parsing error.
16    #[error("JSON parsing error: {0}")]
17    Json(#[from] serde_json::Error),
18
19    /// Custom parsing error with message.
20    #[error("Parse error: {0}")]
21    Parse(String),
22
23    /// Rate limiting error with optional retry-after information.
24    #[error("Rate limited by server{0}", .retry_after.map(|s| format!(" (retry after {s}s)")).unwrap_or_default())]
25    RateLimited {
26        /// Optional retry-after value in seconds from server.
27        retry_after: Option<u64>,
28    },
29
30    /// Package not found.
31    #[error("Package not found")]
32    NotFound,
33
34    /// Invalid input parameter.
35    #[error("Invalid input: {0}")]
36    InvalidInput(String),
37}
38
39/// Result type alias for arch-toolkit operations.
40pub type Result<T> = std::result::Result<T, ArchToolkitError>;