use std::error::Error;
use object_store::Error as ObjectStoreError;
pub type StorageResult<T> = Result<T, StorageError>;
#[derive(Debug, thiserror::Error)]
pub enum StorageError {
#[error("invalid storage path '{path}': {reason}")]
InvalidPath { path: String, reason: String },
#[error("object '{path}' was not found")]
NotFound { path: String },
#[error("disk does not support {capability}")]
UnsupportedCapability { capability: &'static str },
#[error("input stream failed: {0}")]
InputStream(#[source] Box<dyn Error + Send + Sync>),
#[error("storage backend failed: {0}")]
Backend(#[source] ObjectStoreError),
#[error("local disk setup failed: {0}")]
LocalSetup(#[source] ObjectStoreError),
}
impl StorageError {
pub(crate) fn backend(error: ObjectStoreError, path: &str) -> Self {
match error {
ObjectStoreError::NotFound { .. } => Self::NotFound { path: path.to_owned() },
error => Self::Backend(error),
}
}
pub(crate) fn input(error: impl Error + Send + Sync + 'static) -> Self {
Self::InputStream(Box::new(error))
}
}