Skip to main content

chronix_engine/objstore/
error.rs

1//! Object storage error types.
2
3use thiserror::Error;
4
5/// Object storage errors.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum ObjStoreError {
9    /// Underlying object store error.
10    #[error("object store error: {0}")]
11    Store(#[from] object_store::Error),
12
13    /// An uploaded archive object is missing or the wrong size.
14    ///
15    /// Reported as an error rather than a warning because the caller's next
16    /// step after a successful archive is to delete the original.
17    #[error("archive {object}: expected {expected} bytes, found {}", .found.map_or_else(|| "no object".to_string(), |n| n.to_string()))]
18    IntegrityCheckFailed {
19        /// Object-store path that failed verification.
20        object: String,
21        /// Size the local segment had.
22        expected: usize,
23        /// Size found remotely, or `None` if the object is absent.
24        found: Option<usize>,
25    },
26
27    /// Local cache I/O error.
28    #[error("cache I/O error: {0}")]
29    CacheIo(#[source] std::io::Error),
30
31    /// Object not found at the given path.
32    #[error("object not found: {path}")]
33    NotFound {
34        /// The path that was not found.
35        path: String,
36    },
37
38    /// Invalid configuration.
39    #[error("invalid configuration: {detail}")]
40    InvalidConfig {
41        /// Description of the configuration error.
42        detail: String,
43    },
44
45    /// URL parsing error.
46    #[error("invalid URL: {0}")]
47    InvalidUrl(#[from] url::ParseError),
48
49    /// Storage backend compatibility error.
50    #[error("storage error: {0}")]
51    Storage(#[from] crate::storage::StorageError),
52
53    /// Segment read error while re-encoding for the cold tier.
54    #[error("segment error: {0}")]
55    Segment(#[source] crate::segment::SegmentError),
56
57    /// Parquet encode/decode error in the cold tier.
58    #[error("parquet error: {0}")]
59    Parquet(String),
60
61    /// Local file I/O error.
62    #[error("I/O error: {0}")]
63    Io(#[source] std::io::Error),
64}
65
66/// A specialised `Result` type for object storage operations.
67pub type Result<T> = std::result::Result<T, ObjStoreError>;
68
69impl From<ObjStoreError> for crate::storage::StorageError {
70    fn from(e: ObjStoreError) -> Self {
71        match e {
72            ObjStoreError::NotFound { path } => crate::storage::StorageError::NotFound {
73                path: std::path::PathBuf::from(path),
74            },
75            other => crate::storage::StorageError::InvalidPath {
76                detail: other.to_string(),
77            },
78        }
79    }
80}