Skip to main content

sapphire_framework_sync/
error.rs

1//! Error type for the replication core.
2
3use crate::report::PauseReason;
4
5/// Errors raised by the replication core.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    #[error("I/O error: {0}")]
9    Io(#[from] std::io::Error),
10    #[error("replica store error: {0}")]
11    Store(#[from] redb::Error),
12    #[error("serialization error: {0}")]
13    Json(#[from] serde_json::Error),
14    #[error("ignore file error: {0}")]
15    Ignore(#[from] ignore::Error),
16    #[error("replica store format {found} is newer than this build supports ({supported})")]
17    FormatTooNew { found: u32, supported: u32 },
18    #[error("replica store belongs to root {stored:?}, not {requested:?}")]
19    RootMismatch { stored: String, requested: String },
20    #[error("replica store is corrupt: {0}")]
21    Corrupt(String),
22    #[error("replica is paused: {0:?}")]
23    Paused(PauseReason),
24    #[cfg(any(test, feature = "test-util"))]
25    #[error("injected fault")]
26    InjectedFault,
27}
28
29/// Result alias for the replication core.
30pub type Result<T> = std::result::Result<T, Error>;
31
32/// Converts redb's per-operation error types into [`Error::Store`].
33pub(crate) trait RedbExt<T> {
34    fn db(self) -> Result<T>;
35}
36
37impl<T, E: Into<redb::Error>> RedbExt<T> for std::result::Result<T, E> {
38    fn db(self) -> Result<T> {
39        self.map_err(|e| Error::Store(e.into()))
40    }
41}