use opendal::Error;
use opendal::ErrorKind;
pub(crate) fn parse_error(err: object_store::Error) -> Error {
match err {
object_store::Error::NotFound { .. } => {
Error::new(ErrorKind::NotFound, "path not found").set_source(err)
}
object_store::Error::AlreadyExists { .. } => {
Error::new(ErrorKind::AlreadyExists, "path already exists").set_source(err)
}
object_store::Error::PermissionDenied { .. }
| object_store::Error::Unauthenticated { .. } => {
Error::new(ErrorKind::PermissionDenied, "permission denied").set_source(err)
}
object_store::Error::InvalidPath { .. } => {
Error::new(ErrorKind::NotFound, "invalid path").set_source(err)
}
object_store::Error::NotSupported { .. } => {
Error::new(ErrorKind::Unsupported, "operation not supported").set_source(err)
}
object_store::Error::Precondition { .. } => {
Error::new(ErrorKind::ConditionNotMatch, "precondition not met").set_source(err)
}
object_store::Error::Generic { store, .. } => {
Error::new(ErrorKind::Unexpected, format!("{store} operation failed")).set_source(err)
}
_ => Error::new(ErrorKind::Unexpected, "unknown error").set_source(err),
}
}