Skip to main content

timeseries_table_core/storage/
error.rs

1use std::{error::Error, fmt, io};
2
3use snafu::{Backtrace, prelude::*};
4
5/// Errors produced by the storage backend implementation.
6///
7/// Currently this crate only supports a local filesystem backend; backend-specific
8/// I/O errors are wrapped in this enum so higher layers can map them into
9/// StorageError variants with additional context.
10#[derive(Debug)]
11pub enum BackendError {
12    /// A local filesystem I/O error.
13    Local(io::Error),
14}
15
16impl fmt::Display for BackendError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            BackendError::Local(e) => write!(f, "local I/O error: {e}"),
20        }
21    }
22}
23
24impl Error for BackendError {
25    fn source(&self) -> Option<&(dyn Error + 'static)> {
26        match self {
27            BackendError::Local(e) => Some(e),
28        }
29    }
30}
31
32/// Errors that can occur during storage operations.
33#[derive(Debug, Snafu)]
34#[snafu(visibility(pub(crate)))]
35pub enum StorageError {
36    /// The specified path was not found.
37    #[snafu(display("Path not found: {path}"))]
38    NotFound {
39        /// The path that was not found.
40        path: String,
41        /// Underlying backend error that caused the failure.
42        source: BackendError,
43        /// The backtrace at the time the error occurred.
44        backtrace: Backtrace,
45    },
46
47    /// The specified path already exists when creation was requested with
48    /// create-new semantics.
49    #[snafu(display("Path already exists: {path}"))]
50    AlreadyExists {
51        /// The path that was found to already exist.
52        path: String,
53        /// Underlying backend error that indicates the existing resource.
54        source: BackendError,
55        /// The backtrace captured when the error occurred.
56        backtrace: Backtrace,
57    },
58
59    /// An I/O error occurred on the local filesystem.
60    #[snafu(display("Local I/O error at {path}: {source}"))]
61    OtherIo {
62        /// The path where the I/O error occurred.
63        path: String,
64        /// Underlying backend I/O error with platform-specific details.
65        source: BackendError,
66        /// The backtrace at the time the error occurred.
67        backtrace: Backtrace,
68    },
69
70    /// The specified path already exists when creation was requested with
71    /// create-new semantics.
72    #[snafu(display("Path already exists: {path}"))]
73    AlreadyExistsNoSource {
74        /// The path that was found to already exist.
75        path: String,
76
77        /// The backtrace captured when the error occurred.
78        backtrace: Backtrace,
79    },
80}