fcb_core/static_btree/error.rs
1#[cfg(feature = "http")]
2use http_range_client::HttpError;
3use std::io;
4use thiserror::Error; // Import the Error derive macro
5
6/// Custom error type for StaticBTree operations.
7#[derive(Error, Debug)] // Use thiserror::Error derive
8pub enum Error {
9 /// Errors originating from the underlying Read/Seek/Write operations.
10 #[error("io error: {0}")]
11 IoError(#[from] io::Error), // Automatically implements From<io::Error>
12
13 /// Errors indicating the data format is incorrect (e.g., bad magic bytes, wrong version).
14 #[error("invalid format: {0}")]
15 InvalidFormat(String),
16
17 /// Errors during the serialization of a key.
18 #[error("key serialization error: {0}")]
19 KeySerializationError(String),
20
21 /// Errors during the deserialization of a key.
22 #[error("key deserialization error: {0}")]
23 KeyDeserializationError(String),
24
25 /// Errors specific to the tree building process (e.g., unsorted input).
26 #[error("build error: {0}")]
27 BuildError(String),
28
29 /// Errors specific to querying (e.g., trying to access invalid node index).
30 #[error("query error: {0}")]
31 QueryError(String),
32
33 /// Used when an operation requires a feature not yet implemented.
34 #[error("not implemented: {0}")]
35 NotImplemented(String),
36
37 /// Used when an operation fails due to an unexpected condition.
38 #[error("other error: {0}")]
39 Other(String),
40
41 /// Used when an operation fails due to an HTTP error.
42 #[cfg(feature = "http")]
43 #[error("http error: {0}")]
44 HttpError(#[from] HttpError),
45
46 /// Requested payload offset is not in the cache
47 #[error("payload offset not in cache")]
48 PayloadOffsetNotInCache,
49}
50
51pub type Result<T> = std::result::Result<T, Error>;