use indicatif;
use reqwest;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum OpenStackCliError {
#[error("failed to serialize data to json: {}", source)]
SerializeJson {
#[from]
source: serde_json::Error,
},
#[error(
"failed to deserialize data to json. Try using `-o json` to still see the data. \n\t{}",
data
)]
DeserializeJson {
source: serde_json::Error,
data: String,
},
#[error("authentication error")]
Auth {
source: openstack_sdk::OpenStackError,
},
#[error("error changing scope to {:?}", scope)]
ReScope {
scope: openstack_sdk::auth::authtoken::AuthTokenScope,
source: openstack_sdk::OpenStackError,
},
#[error(transparent)]
OpenStackSDK {
#[from]
source: openstack_sdk::OpenStackError,
},
#[error(transparent)]
OpenStackApi {
#[from]
source: openstack_sdk::api::ApiError<openstack_sdk::RestError>,
},
#[error(transparent)]
CliConfig {
#[from]
source: crate::config::ConfigError,
},
#[error(transparent)]
CloudConfig {
#[from]
source: openstack_sdk::config::ConfigError,
},
#[error(transparent)]
OpenStackCatalog {
#[from]
source: openstack_sdk::catalog::CatalogError,
},
#[error("command has no subcommands")]
NoSubcommands,
#[error("resource not found")]
ResourceNotFound,
#[error("cannot find resource by identifier")]
IdNotUnique,
#[error("cannot find resource attribute {0}")]
ResourceAttributeMissing(String),
#[error("resource attribute {0} is not a string")]
ResourceAttributeNotString(String),
#[error("IO error: {}", source)]
IO {
#[from]
source: std::io::Error,
},
#[error("reqwest error: {}", source)]
Reqwest {
#[from]
source: reqwest::Error,
},
#[error("argument parsing error: {}", source)]
Clap {
#[from]
source: clap::error::Error,
},
#[error("indicativ error: {}", source)]
Idinticatif {
#[from]
source: indicatif::style::TemplateError,
},
#[error("OpenStackSDK endpoint builder error: `{0}`")]
EndpointBuild(String),
#[error("cloud connection `{0:?}` cannot be found")]
ConnectionNotFound(String),
#[error("invalid header name `{}`", source)]
InvalidHeaderName {
#[from]
source: http::header::InvalidHeaderName,
},
#[error("invalid header value `{}`", source)]
InvalidHeaderValue {
#[from]
source: http::header::InvalidHeaderValue,
},
#[error("invalid url: {}", source)]
InvalidUri {
#[from]
source: http::uri::InvalidUri,
},
#[error("dialoguer error `{}`", source)]
DialoguerError {
#[from]
source: dialoguer::Error,
},
#[error("input parameters error: {0}")]
InputParameters(String),
#[error(transparent)]
Base64Decode(#[from] base64::DecodeError),
#[error("valid authentication is missing to be able to rescope the session")]
MissingValidAuthenticationForRescope,
#[error(transparent)]
UrlParse {
#[from]
source: url::ParseError,
},
#[error(transparent)]
Other(#[from] eyre::Report),
}
impl OpenStackCliError {
pub fn deserialize(error: serde_json::Error, data: String) -> Self {
Self::DeserializeJson {
source: error,
data,
}
}
}