use crate::Diagnostic;
use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BundleError {
#[error("bundle validation failed")]
Validation(Vec<Diagnostic>),
#[error("failed to parse manifest {path}: {message}")]
Manifest { path: PathBuf, message: String },
#[error("failed to parse JSON {path}: {message}")]
Json { path: String, message: String },
#[error("filesystem error for {path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("key error: {0}")]
Key(String),
#[error("the signing key is encrypted and requires a password")]
SigningKeyPasswordRequired,
#[error("invalid bundle archive: {0}")]
Archive(String),
#[error("bundle {kind} size exceeds the configured limit of {limit} bytes")]
SizeLimit { kind: &'static str, limit: usize },
#[error("serialization failed: {0}")]
Serialization(String),
}
impl BundleError {
pub fn is_validation(&self) -> bool {
matches!(
self,
Self::Validation(_)
| Self::Manifest { .. }
| Self::Json { .. }
| Self::Archive(_)
| Self::SizeLimit { .. }
)
}
pub fn diagnostics(&self) -> &[Diagnostic] {
match self {
Self::Validation(diagnostics) => diagnostics,
_ => &[],
}
}
pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Self::Io {
path: path.into(),
source,
}
}
}
pub type Result<T> = std::result::Result<T, BundleError>;