Skip to main content

fasm_storage/flatdir/
error.rs

1//! The error type shared by the layout machinery and the flat backends.
2
3use std::error::Error;
4
5use crate::error::RetryableStorageError;
6use crate::key::KeyError;
7
8/// A flat-layout store failed a structural precondition.
9///
10/// Every variant is non-retryable except `Engine`, which delegates to the
11/// engine view's own classification; for today's backends that is also
12/// non-retryable.
13#[derive(Debug, thiserror::Error)]
14pub enum FlatError<E> {
15    /// The store's version row names a layout this build does not read
16    /// (a newer major version, a read-only newer minor version, or a
17    /// value that is not a 12-byte version at all).
18    #[error("store content does not match this layout version")]
19    Foreign,
20    /// A structural row (version, HCA counter or recent, node row) is
21    /// malformed, or the allocator produced a state the layout cannot
22    /// have produced (a prefix already in use, a corrupt counter).
23    #[error("store content is malformed")]
24    Corrupt,
25    /// A directory path failed validation.
26    #[error(transparent)]
27    Key(KeyError),
28    /// The engine view failed.
29    #[error("{0}")]
30    Engine(#[from] E),
31}
32
33impl<E: std::fmt::Debug + PartialEq> PartialEq for FlatError<E> {
34    fn eq(&self, other: &Self) -> bool {
35        match (self, other) {
36            (Self::Foreign, Self::Foreign) | (Self::Corrupt, Self::Corrupt) => true,
37            (Self::Key(a), Self::Key(b)) => a == b,
38            (Self::Engine(a), Self::Engine(b)) => a == b,
39            _ => false,
40        }
41    }
42}
43
44impl<E: Error + RetryableStorageError> RetryableStorageError for FlatError<E> {
45    fn is_retryable(&self) -> bool {
46        match self {
47            FlatError::Engine(e) => e.is_retryable(),
48            _ => false,
49        }
50    }
51}