hyveos_sdk/
error.rs

1use std::{io, path::PathBuf};
2
3use tonic::{transport::Error as TransportError, Status};
4
5/// The error type for the SDK.
6///
7/// This error type is used throughout the SDK to represent all possible errors that can occur.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10    /// An IO error occurred.
11    #[error("IO error: {0}")]
12    Io(#[from] io::Error),
13    /// A Tonic transport error occurred.
14    #[error("Tonic transport error: {0}")]
15    Transport(#[from] TransportError),
16    /// A Tonic status error occurred.
17    #[error("Tonic error: {0}")]
18    Status(#[from] Status),
19    /// An error occurred while serializing or deserializing data to/from JSON.
20    #[cfg(feature = "json")]
21    #[error("JSON (de-)serialization error: {0}")]
22    Json(#[from] serde_json::Error),
23    /// An error occurred while serializing or deserializing data to/from CBOR.
24    #[cfg(feature = "cbor")]
25    #[error("CBOR (de-)serialization error: {0}")]
26    Cbor(#[from] serde_cbor::Error),
27    /// An error occurred while parsing a `PeerId`.
28    #[error("PeerId parsing error: {0}")]
29    PeerId(#[from] libp2p_identity::ParseError),
30    /// An error from the core library.
31    #[error(transparent)]
32    Core(#[from] hyveos_core::Error),
33    /// An environment variable was expected to be set, but it wasn't.
34    #[error("Could not get {0}: {1}")]
35    EnvVarMissing(&'static str, #[source] std::env::VarError),
36    /// A path was expected to have a file name, but it didn't.
37    #[error("Path has no file name: {}", .0.display())]
38    NoFileName(PathBuf),
39    /// An error occurred while parsing a URI.
40    #[cfg(feature = "network")]
41    #[error("Invalid URI: {0}")]
42    InvalidUri(#[from] http::uri::InvalidUri),
43    /// An error occurred while parsing URI parts.
44    #[cfg(feature = "network")]
45    #[error("Invalid URI: {0}")]
46    InvalidUriParts(#[from] http::uri::InvalidUriParts),
47    /// An error occurred while parsing a URL.
48    #[cfg(feature = "network")]
49    #[error("Invalid URL: {0}")]
50    InvalidUrl(#[from] url::ParseError),
51    #[cfg(feature = "network")]
52    /// An error occurred while sending a request.
53    #[error("Request error: {0}")]
54    Reqwest(#[from] reqwest::Error),
55    #[cfg(feature = "network")]
56    /// Got an error response from a HTTP request.
57    #[error("Got an error response: {0}")]
58    Response(String),
59}
60
61/// Alias for a `Result` that defaults to [`Error`] as the error type.
62pub type Result<T, E = Error> = std::result::Result<T, E>;