hermit/src/error.rs

33 lines
925 B
Rust

//! Defines the [`Error`] type, [`Result`] shorthand and [`err`] utility function to convert
//! compatible errors to `Error`.
use derive_more::From;
use crate::ap;
/// A result type that defaults to using [`Error`] as the second type
/// parameter.
pub type Result <T, E = Error> = std::result::Result<T, E>;
/// Errors generated within Hermit.
#[derive(Debug, From)]
pub enum Error {
/// [`reqwest`] errors.
Http (reqwest::Error),
/// [`serde_json`] errors.
Json (serde_json::Error),
/// [`sqlx`] errors.
Sqlx (sqlx::Error),
/// A cryptography error from [`openssl`].
OpenSSL (openssl::error::ErrorStack),
/// An error with parsing a [`url`].
Url (url::ParseError),
/// An error in converting between models.
Invalid (ap::Invalid),
/// Generic "timed out" error.
Timeout,
}
/// Trivial conversion function for use in `map_err` functions.
pub (crate) fn err (e: impl Into<Error>) -> Error { e.into() }