sos_filesystem/
error.rs

1use sos_core::commit::CommitHash;
2use std::path::PathBuf;
3use thiserror::Error;
4
5/// Errors generated by the filesystem library.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Error generated when a vault identity byte is wrong.
9    #[error("bad identity byte {0:#04x} at position {1} expecting {2}")]
10    BadIdentity(u8, usize, String),
11
12    /// Error generated when a buffer used to read identity bytes
13    /// is not long enough.
14    #[error("buffer passed for identity check is too short")]
15    IdentityLength,
16
17    /// Error generated when a target commit hash could not be found.
18    #[error("commit '{0}' could not be found")]
19    CommitNotFound(CommitHash),
20
21    /// Error generated when replacing events in an event log
22    /// does not compute the same root hash as the expected
23    /// checkpoint.
24    #[error("checkpoint verification failed, expected root hash '{checkpoint}' but computed '{computed}', snapshot rollback completed: '{rollback_completed}' (snapshot: '{snapshot:?}')")]
25    CheckpointVerification {
26        /// Checkpoint root hash.
27        checkpoint: CommitHash,
28        /// Computed root hash.
29        computed: CommitHash,
30        /// Snapshot path.
31        snapshot: Option<PathBuf>,
32        /// Whether a rollback completed.
33        rollback_completed: bool,
34    },
35
36    /// Error generated trying to rewind an event log.
37    #[error("rewind failed as pruned commits is greater than the length of the in-memory tree")]
38    RewindLeavesLength,
39
40    /// Errors generated by the core library.
41    #[error(transparent)]
42    Core(#[from] sos_core::Error),
43
44    /// Errors generated by the vault library.
45    #[error(transparent)]
46    Vault(#[from] sos_vault::Error),
47
48    /// Error generated converting to fixed length slice.
49    #[error(transparent)]
50    TryFromSlice(#[from] std::array::TryFromSliceError),
51
52    /// Errors generated by the IO module.
53    #[error(transparent)]
54    Io(#[from] std::io::Error),
55
56    /// Errors generated by the JSON library.
57    #[error(transparent)]
58    Json(#[from] serde_json::Error),
59}