use thiserror::Error;
#[derive(Error, Debug)]
pub enum KonarrError {
#[error("Failed to parse the configuration file: {0}")]
ConfigParseError(String),
#[error("IO Error: {0}")]
IOError(#[from] std::io::Error),
#[error("IO Error: {0}")]
YamlError(#[from] serde_yaml::Error),
#[error("JSON Error: {0}")]
JsonError(#[from] serde_json::Error),
#[error("Figment Error")]
FigmentError(#[from] figment::Error),
#[error("Version Error")]
VersionError(#[from] semver::Error),
#[error("Failed to parse SBOM: {0}")]
ParseSBOM(String),
#[error("PURL parsing error")]
PurlError(#[from] purl::ParseError),
#[error("Failed to index data: {0}")]
IndexingError(String),
#[error("Invalid Data: {0}")]
InvalidData(String),
#[error("Authentication Error: {0}")]
AuthenticationError(String),
#[error("Unauthorized")]
Unauthorized,
#[cfg(feature = "client")]
#[error("KonarrClient API Error: {0}")]
KonarrClient(String),
#[cfg(feature = "models")]
#[error("{0}")]
GeekOrm(#[from] geekorm::Error),
#[cfg(feature = "models")]
#[error("{0}")]
Libsql(#[from] libsql::Error),
#[cfg(feature = "tools")]
#[error("Tool Error: {0}")]
ToolError(String),
#[error("Lock Error: {0}")]
LockError(String),
#[error("{0}")]
FromUtf8Error(#[from] std::string::FromUtf8Error),
#[error("{0}")]
ParseDateTimeError(#[from] chrono::ParseError),
#[error("{0}")]
UrlParseError(#[from] url::ParseError),
#[cfg(feature = "client")]
#[error("{0}")]
ReqwestError(#[from] reqwest::Error),
#[cfg(feature = "docker")]
#[error("{0}")]
BollardError(#[from] bollard::errors::Error),
#[error("Unknown Error: {0}")]
UnknownError(String),
}
#[cfg(feature = "client")]
impl From<crate::client::ApiError> for KonarrError {
fn from(error: crate::client::ApiError) -> Self {
if let Some(details) = error.details {
KonarrError::KonarrClient(format!("{} - {}", error.message, details))
} else {
KonarrError::KonarrClient(error.message)
}
}
}