libsql_wal/storage/
error.rs

1use std::panic::Location;
2
3use super::backend::FindSegmentReq;
4
5#[derive(thiserror::Error, Debug)]
6pub enum Error {
7    #[error("io error: {0}")]
8    Io(#[from] std::io::Error),
9    #[error("an error occured while storing a segment: {0}")]
10    Store(String),
11    #[error("error compacting segment: {0}")]
12    Compact(#[from] crate::error::Error),
13    #[error("segment not found for request {0:?}")]
14    SegmentNotFound(FindSegmentReq),
15    #[error("unhandled storage error: {error}, in {context}")]
16    UnhandledStorageError {
17        error: Box<dyn std::error::Error + Send + Sync + 'static>,
18        context: String,
19        loc: String,
20    },
21    // We may recover from this error, and rebuild the index from the data file.
22    #[error("invalid index: {0}")]
23    InvalidIndex(&'static str),
24    #[error("Provided config is of an invalid type")]
25    InvalidConfigType,
26}
27
28impl Error {
29    #[track_caller]
30    pub(crate) fn unhandled(
31        e: impl std::error::Error + Send + Sync + 'static,
32        ctx: impl Into<String>,
33    ) -> Self {
34        Self::UnhandledStorageError {
35            error: Box::new(e),
36            context: ctx.into(),
37            loc: Location::caller().to_string(),
38        }
39    }
40}