Skip to main content

aurelin_framework/storage/
error.rs

1use std::error::Error;
2
3use object_store::Error as ObjectStoreError;
4
5/// Result returned by filesystem operations.
6pub type StorageResult<T> = Result<T, StorageError>;
7
8/// A filesystem failure with path and capability errors separated from backend failures.
9#[derive(Debug, thiserror::Error)]
10pub enum StorageError {
11    /// The application supplied an unsafe or malformed relative path.
12    #[error("invalid storage path '{path}': {reason}")]
13    InvalidPath { path: String, reason: String },
14
15    /// The requested object does not exist.
16    #[error("object '{path}' was not found")]
17    NotFound { path: String },
18
19    /// The selected disk does not provide the requested capability.
20    #[error("disk does not support {capability}")]
21    UnsupportedCapability { capability: &'static str },
22
23    /// Reading a caller-provided stream failed.
24    #[error("input stream failed: {0}")]
25    InputStream(#[source] Box<dyn Error + Send + Sync>),
26
27    /// The underlying object store failed.
28    #[error("storage backend failed: {0}")]
29    Backend(#[source] ObjectStoreError),
30
31    /// Local disk setup failed.
32    #[error("local disk setup failed: {0}")]
33    LocalSetup(#[source] ObjectStoreError),
34}
35
36impl StorageError {
37    pub(crate) fn backend(error: ObjectStoreError, path: &str) -> Self {
38        match error {
39            ObjectStoreError::NotFound { .. } => Self::NotFound { path: path.to_owned() },
40            error => Self::Backend(error),
41        }
42    }
43
44    pub(crate) fn input(error: impl Error + Send + Sync + 'static) -> Self {
45        Self::InputStream(Box::new(error))
46    }
47}