pub mod user;
pub use user::*;
use wildland_corex::api::SfoError;
use wildland_corex::catlib_service::entities::PubKeyError;
use wildland_corex::catlib_service::error::CatlibError;
use wildland_corex::{
ContainerManagerError,
CoreXError,
CryptoError,
ForestIdentityCreationError,
ForestRetrievalError,
LssError,
PathResolutionError,
StorageTemplateError,
};
use wildland_databases::error::ClientCreationError;
use wildland_dfs::DfsFrontendError;
use wildland_http_client::error::WildlandHttpClientError;
use wildland_http_client::HttpError;
use super::api::container::AddStorageError;
use crate::api::cargo_user::{AutomountError, SharingError};
use crate::api::config::ParseConfigError;
use crate::api::foundation_storage::FsaError;
use crate::api::storage::QuotaControlError;
use crate::multidevice_state::error::MultideviceStateError;
pub trait ExceptionTrait: ToString {
fn reason(&self) -> String {
self.to_string()
}
fn category(&self) -> ErrorCategory;
}
#[derive(Debug)]
#[repr(C)]
pub enum ErrorCategory {
General,
NetworkConnectivity,
Database,
Logical,
Cryptography,
Auth,
ExternalService,
InvalidInputFormat,
Dfs,
}
impl ExceptionTrait for ForestIdentityCreationError {
fn category(&self) -> ErrorCategory {
match self {
ForestIdentityCreationError::CryptoIdentityNotFound => ErrorCategory::Database,
ForestIdentityCreationError::KeyDeriveError(_) => ErrorCategory::Cryptography,
}
}
}
impl ExceptionTrait for CryptoError {
fn category(&self) -> ErrorCategory {
match self {
CryptoError::EntropyTooLow => ErrorCategory::InvalidInputFormat,
_ => ErrorCategory::Cryptography,
}
}
}
impl ExceptionTrait for CoreXError {
fn category(&self) -> ErrorCategory {
match self {
CoreXError::CatlibErr(_, x) => x.category(),
CoreXError::CryptoErr(_, x) => x.category(),
CoreXError::LSSErr(_, x) => x.category(),
CoreXError::CannotCreateForestIdentityError(_) => ErrorCategory::Cryptography,
CoreXError::IdentityReadError(_) => ErrorCategory::Database,
CoreXError::Generic(_) => ErrorCategory::General,
CoreXError::SfoErr(_, _) => ErrorCategory::General,
}
}
}
impl ExceptionTrait for StorageTemplateError {
fn category(&self) -> ErrorCategory {
match self {
StorageTemplateError::CatlibErr(_, x) => x.category(),
StorageTemplateError::SerdeErr(_) => ErrorCategory::InvalidInputFormat,
StorageTemplateError::TemplateEngineErr(_) => ErrorCategory::InvalidInputFormat,
}
}
}
impl ExceptionTrait for AddStorageError {
fn category(&self) -> ErrorCategory {
match self {
AddStorageError::CatlibErr(x) => x.category(),
AddStorageError::StorageTemplateError(x) => x.category(),
}
}
}
impl ExceptionTrait for UserRetrievalError {
fn category(&self) -> ErrorCategory {
match self {
UserRetrievalError::ForestRetrievalError(x) => x.category(),
UserRetrievalError::LssError(x) => x.category(),
UserRetrievalError::CatlibError(x) => x.category(),
UserRetrievalError::ForestNotFound(_) => ErrorCategory::Logical,
UserRetrievalError::DeviceMetadataNotFound => ErrorCategory::Database,
UserRetrievalError::UserNotFound => ErrorCategory::Database,
UserRetrievalError::AutomountError(_, x) => x.category(),
}
}
}
impl ExceptionTrait for AutomountError {
fn category(&self) -> ErrorCategory {
match self {
AutomountError::MultideviceStateError(x) => x.category(),
AutomountError::ContainerManagerError(x) => x.category(),
AutomountError::CatlibError(x) => x.category(),
AutomountError::MountedContainersDetected => ErrorCategory::Logical,
}
}
}
impl ExceptionTrait for SharingError {
fn category(&self) -> ErrorCategory {
match self {
SharingError::Generic(_) => ErrorCategory::General,
}
}
}
impl ExceptionTrait for PubKeyError {
fn category(&self) -> ErrorCategory {
match self {
PubKeyError::KeySizeMismatch => ErrorCategory::Logical,
}
}
}
impl ExceptionTrait for ContainerManagerError {
fn category(&self) -> ErrorCategory {
match self {
ContainerManagerError::AlreadyMounted => ErrorCategory::Logical,
ContainerManagerError::MountingError(_) => ErrorCategory::Dfs,
ContainerManagerError::MalformedManifest(_) => ErrorCategory::Database,
ContainerManagerError::ContainerNotMounted => ErrorCategory::Logical,
ContainerManagerError::NoValidStorages => ErrorCategory::Logical,
}
}
}
impl ExceptionTrait for MultideviceStateError {
fn category(&self) -> ErrorCategory {
match self {
MultideviceStateError::IoError(_) => ErrorCategory::NetworkConnectivity,
MultideviceStateError::Unknown(_) => ErrorCategory::General,
MultideviceStateError::Authentication(_) => ErrorCategory::Auth,
MultideviceStateError::Server(_) => ErrorCategory::Database,
}
}
}
impl ExceptionTrait for ForestRetrievalError {
fn category(&self) -> ErrorCategory {
match self {
ForestRetrievalError::LssError(x) => x.category(),
ForestRetrievalError::KeypairParseError(_) => ErrorCategory::Cryptography,
}
}
}
impl ExceptionTrait for UserCreationError {
fn category(&self) -> ErrorCategory {
match self {
UserCreationError::UserAlreadyExists => ErrorCategory::Logical,
UserCreationError::UserRetrievalError(x) => x.category(),
UserCreationError::LssError(_, x) => x.category(),
UserCreationError::CatlibError(_, _) => ErrorCategory::Database,
_ => ErrorCategory::General,
}
}
}
impl ExceptionTrait for WildlandHttpClientError {
fn category(&self) -> ErrorCategory {
match self {
WildlandHttpClientError::ApplicationHttpError(_) => ErrorCategory::Auth,
WildlandHttpClientError::ClientHttpError(z) => match z {
HttpError::Io(_) => ErrorCategory::NetworkConnectivity,
HttpError::User(_) => ErrorCategory::Logical,
HttpError::Other(_) => ErrorCategory::General,
},
WildlandHttpClientError::ClientConnectivityError(_) => {
ErrorCategory::NetworkConnectivity
}
WildlandHttpClientError::CommonLibError(_) => ErrorCategory::Logical,
}
}
}
impl ExceptionTrait for FsaError {
fn category(&self) -> ErrorCategory {
match self {
FsaError::CryptoError(x) => x.category(),
FsaError::LssError(x) => x.category(),
FsaError::CatlibError(x) => x.category(),
FsaError::StorageTemplateError(x) => x.category(),
FsaError::ConnectivityIssue(_) => ErrorCategory::NetworkConnectivity,
FsaError::EvsError(_, x) => x.category(),
FsaError::UnexpectedResponse(_) => ErrorCategory::Logical,
}
}
}
impl ExceptionTrait for LssError {
fn category(&self) -> ErrorCategory {
ErrorCategory::Database
}
}
impl ExceptionTrait for SfoError {
fn category(&self) -> ErrorCategory {
match self {
SfoError::Generic(_) => ErrorCategory::General,
SfoError::FileExists => ErrorCategory::General,
SfoError::FileNotFound => ErrorCategory::General,
}
}
}
impl ExceptionTrait for ParseConfigError {
fn category(&self) -> ErrorCategory {
ErrorCategory::InvalidInputFormat
}
}
impl ExceptionTrait for CreateMnemonicError {
fn category(&self) -> ErrorCategory {
ErrorCategory::InvalidInputFormat
}
}
impl ExceptionTrait for CatlibError {
fn category(&self) -> ErrorCategory {
match self {
CatlibError::NoRecordsFound => ErrorCategory::Database,
CatlibError::RecordAlreadyExists => ErrorCategory::Database,
CatlibError::DatabaseIoError(_) => ErrorCategory::Database,
CatlibError::UnexpectedError(_) => ErrorCategory::Database,
CatlibError::DatabaseAuthError(_) => ErrorCategory::Auth,
CatlibError::DatabaseServerError(_) => ErrorCategory::Database,
CatlibError::InvalidDataError(_) => ErrorCategory::Database,
}
}
}
impl ExceptionTrait for DfsFrontendError {
fn category(&self) -> ErrorCategory {
match self {
DfsFrontendError::PathResolutionError(x) => x.category(),
DfsFrontendError::Generic(_) => ErrorCategory::General,
_ => ErrorCategory::Dfs,
}
}
}
impl ExceptionTrait for PathResolutionError {
fn category(&self) -> ErrorCategory {
match self {
PathResolutionError::CatlibError(x) => x.category(),
PathResolutionError::Generic(_) => ErrorCategory::General,
PathResolutionError::CoreXError(x) => x.category(),
}
}
}
impl ExceptionTrait for ClientCreationError {
fn category(&self) -> ErrorCategory {
match self {
ClientCreationError::Unknown(_) => ErrorCategory::General,
ClientCreationError::Authentication(_) => ErrorCategory::Auth,
ClientCreationError::IoError(_) => ErrorCategory::NetworkConnectivity,
}
}
}
impl ExceptionTrait for QuotaControlError {
fn category(&self) -> ErrorCategory {
match self {
QuotaControlError::CoreXError(_, e) => e.category(),
QuotaControlError::DfsFrontendError(_, e) => e.category(),
}
}
}