use std::path::PathBuf;
use oci_distribution::Reference;
use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum OciError {
#[error("No version found in annotations")]
NoVersion(),
#[error("No manifest found in package")]
NoManifest,
#[error("Invalid manifest found at {}. Try deleting your cache directory.",.0.display())]
InvalidManifest(PathBuf),
#[error("Reference '{0}' did not contain a tag or digest")]
NoTagOrDigest(String),
#[error("Configuration disallows fetching artifacts with the :latest tag ({0})")]
LatestDisallowed(String),
#[error("Could not fetch '{0}': {1}")]
OciFetchFailure(String, String),
#[error("Could not untar '{0}': {1}")]
UntarFile(String, String),
#[error("Could not push '{0}': {1}")]
OciPushFailure(Reference, Box<dyn std::error::Error + Send + Sync>),
#[error("Could not push manifest list '{0}': {1}")]
OciPushManifestListFailure(Reference, Box<dyn std::error::Error + Send + Sync>),
#[error("Could not retrieve manifest for '{0}': {1}")]
OciPullManifestFailure(Reference, Box<dyn std::error::Error + Send + Sync>),
#[error("Could not parse OCI URL {0}: {1}")]
OCIParseError(String, String),
#[error(transparent)]
IOError(#[from] std::io::Error),
#[error(transparent)]
OciDistribution(#[from] oci_distribution::errors::OciDistributionError),
#[error(transparent)]
JsonParseFailed(#[from] serde_json::Error),
#[error(transparent)]
YamlParseFailed(#[from] serde_yaml::Error),
#[error("Failed to parse the image reference: {0}")]
InvalidReferenceFormat(String),
#[error("Failed to pull the package: {0}")]
PullFailed(String),
#[error("Wick package layers must contain a title")]
NoTitle,
#[error("Failed to create directory '{0}': {1}")]
CreateDir(PathBuf, #[source] std::io::Error),
#[error("Failed to write file '{0}': {1}")]
WriteFile(PathBuf, #[source] std::io::Error),
#[error("Published components must be named")]
NoName,
#[error("Invalid layer path '{0}', layer path must contain at least one forward slash.")]
InvalidLayerPath(PathBuf),
#[error("Invalid cache location '{0}'")]
InvalidCache(wick_xdg::Error),
#[error("Failed to read downloaded package: {0}")]
PackageReadFailed(String),
#[error("Failed to push the package: {0}")]
PushFailed(String),
#[error("Refusing to overwrite {}. Set 'overwrite' to true to force.", .0.iter().map(|v|v.display().to_string()).collect::<Vec<_>>().join(", "))]
WouldOverwrite(Vec<PathBuf>),
}