use std::fmt;
pub type Result<Value> = std::result::Result<Value, Error>;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
InputOutput(std::io::Error),
InvalidFormat {
details: String,
},
SegmentNotFound {
segment_identifier: crate::segment::identifier::SegmentIdentifier,
},
ExternalBinaryContentUnavailable {
blob_identifier: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InputOutput(source) => write!(formatter, "input/output error: {source}"),
Error::InvalidFormat { details } => {
write!(formatter, "invalid segment-tar data: {details}")
}
Error::SegmentNotFound { segment_identifier } => {
write!(
formatter,
"segment {segment_identifier} not found in any archive"
)
}
Error::ExternalBinaryContentUnavailable { blob_identifier } => {
write!(
formatter,
"binary {blob_identifier} is stored in an external blob store; \
only its identifier is available"
)
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::InputOutput(source) => Some(source),
Error::InvalidFormat { .. }
| Error::SegmentNotFound { .. }
| Error::ExternalBinaryContentUnavailable { .. } => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(source: std::io::Error) -> Self {
Error::InputOutput(source)
}
}