qcs_api_client_common/configuration/
error.rsuse std::{error::Error, path::PathBuf};
use super::ClientConfigurationBuilderError;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum LoadError {
#[error("Failed to load settings: {0}")]
Load(Box<dyn Error + Send + Sync + 'static>),
#[error("Failed to load value from the environment variable {variable_name}: {message}")]
EnvVar {
variable_name: String,
message: String,
},
#[error("Failed to load file from path {path:?}: {message}")]
Path {
path: PathBuf,
message: String,
},
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("Failed to build the ClientConfiguration: {0}")]
Build(#[from] ClientConfigurationBuilderError),
#[error("Expected profile {0} in settings.profiles but it does not exist")]
ProfileNotFound(String),
#[error("Expected auth server {0} in settings.auth_servers but it does not exist")]
AuthServerNotFound(String),
#[cfg(feature = "tracing-config")]
#[error("Could not parse tracing filter: {0}")]
TracingFilterParseError(#[from] crate::tracing_configuration::TracingFilterError),
}
impl<E: Error + 'static> From<shellexpand::LookupError<E>> for LoadError {
fn from(value: shellexpand::LookupError<E>) -> Self {
Self::EnvVar {
variable_name: value.var_name,
message: value.cause.to_string(),
}
}
}
impl From<figment::Error> for LoadError {
fn from(value: figment::Error) -> Self {
Self::Load(Box::new(value))
}
}
#[derive(Debug, thiserror::Error)]
pub enum TokenError {
#[error("No refresh token is configured within the selected QCS credential.")]
NoRefreshToken,
#[error("No access token has been requested.")]
NoAccessToken,
#[error("Requested an access token for a configuration without credentials.")]
NoCredentials,
#[error("The access token is invalid: {0}")]
InvalidAccessToken(jsonwebtoken::errors::Error),
#[error("No auth server is configured within the selected QCS credential.")]
NoAuthServer,
#[error("Error fetching new token from the QCS API: {0}")]
Fetch(#[from] reqwest::Error),
#[error("Failed to request an externally managed access token: {0}")]
ExternallyManaged(String),
#[error("Failed to write the new access token to the secrets file: {0}")]
Write(#[from] WriteError),
}
#[derive(Debug, thiserror::Error)]
pub enum WriteError {
#[error(transparent)]
IoWithPath(#[from] IoErrorWithPath),
#[error("File could not be read as TOML: {0}")]
InvalidToml(#[from] toml_edit::TomlError),
#[error("The table `{0}` does not exist.")]
MissingTable(String),
#[error("Error formatting time: {0}.")]
TimeFormat(#[from] time::error::Format),
#[error("Error writing or persisting temporary secrets file during access token refresh: {0}")]
TempFile(#[from] async_tempfile::Error),
}
#[derive(Debug)]
pub enum IoOperation {
Open,
Read,
Write,
Rename { dest: PathBuf },
GetMetadata,
SetPermissions,
Flush,
}
#[derive(Debug, thiserror::Error)]
#[error("Io error while error performing {operation:?} on {path}: {error}")]
pub struct IoErrorWithPath {
#[source]
pub error: std::io::Error,
pub path: PathBuf,
pub operation: IoOperation,
}