runpod_sdk/
error.rs

1//! Error types for the RunPod SDK.
2
3use crate::builder::RunpodBuilderError;
4
5/// Error type for RunPod API operations.
6///
7/// This enum represents all possible errors that can occur when using the RunPod SDK,
8/// from HTTP transport errors to API-specific failures and configuration issues.
9///
10/// # Examples
11///
12/// Handling different error types:
13///
14/// ```no_run
15/// # use runpod_sdk::{Error, Result, RunpodClient};
16/// # use runpod_sdk::service::PodsService;
17/// # async fn example() -> Result<()> {
18/// let client: RunpodClient = RunpodClient::from_env()?;
19///
20/// match client.list_pods(Default::default()).await {
21///     Ok(pods) => println!("Found {} pods", pods.len()),
22///     Err(Error::Http(e)) => println!("Network error: {}", e),
23///     Err(Error::Config(e)) => println!("Configuration error: {}", e),
24///     Err(e) => println!("Other error: {}", e),
25/// }
26/// # Ok(())
27/// # }
28/// ```
29#[non_exhaustive]
30#[derive(Debug, thiserror::Error)]
31pub enum Error {
32    /// HTTP transport error from the underlying HTTP client.
33    ///
34    /// This includes network connectivity issues, DNS resolution failures,
35    /// timeout errors, and other transport-layer problems.
36    #[error("HTTP error: {0}")]
37    Http(#[from] reqwest::Error),
38
39    /// JSON serialization/deserialization error.
40    ///
41    /// This occurs when the SDK fails to parse API responses or serialize
42    /// request payloads to/from JSON.
43    #[cfg(feature = "serverless")]
44    #[cfg_attr(docsrs, doc(cfg(feature = "serverless")))]
45    #[error("Serialization error: {0}")]
46    Serialization(#[from] serde_json::Error),
47
48    /// Configuration error.
49    ///
50    /// This occurs when configuration parameters are invalid or when using
51    /// the configuration builder and validation fails during the build process.
52    #[error("Configuration error: {0}")]
53    Config(#[from] RunpodBuilderError),
54
55    /// Job operation error.
56    ///
57    /// This occurs when attempting to perform operations on a job that is in an invalid state.
58    #[cfg(feature = "serverless")]
59    #[cfg_attr(docsrs, doc(cfg(feature = "serverless")))]
60    #[error("Job error: {0}")]
61    Job(String),
62}
63
64/// Result type for RunPod API operations.
65///
66/// This is a convenience type alias for `std::result::Result<T, Error>` that is used
67/// throughout the RunPod SDK. All SDK methods that can fail return this Result type.
68pub type Result<T, E = Error> = std::result::Result<T, E>;