Skip to main content

newton_bootnode/
error.rs

1//! Bootnode error types.
2
3/// Errors returned by bootnode operations.
4#[derive(Debug, thiserror::Error)]
5pub enum BootnodeError {
6    /// The latest snapshot is older than the consumer-configured maximum.
7    ///
8    /// Emitted by consumers (e.g., operator bootstrap per §S.19), never
9    /// constructed inside this crate.
10    #[error("snapshot too stale: age {age_secs}s exceeds max {max_allowed}s")]
11    SnapshotTooStale {
12        /// Age of the snapshot in seconds.
13        age_secs: u64,
14        /// Consumer-configured staleness ceiling.
15        max_allowed: u64,
16    },
17
18    /// On-disk snapshot has an unrecognised `format_version`.
19    #[error("unsupported snapshot format version: {0}")]
20    UnsupportedSnapshotFormat(u8),
21
22    /// On-disk delta entry has an unrecognised `format_version`.
23    #[error("unsupported delta format version: {0}")]
24    UnsupportedDeltaFormat(u8),
25
26    /// Filesystem I/O error (e.g. parent directory creation).
27    #[error("io: {0}")]
28    Io(#[from] std::io::Error),
29
30    /// redb database error.
31    #[error("redb: {0}")]
32    Database(#[from] redb::DatabaseError),
33
34    /// redb table error.
35    #[error("redb table: {0}")]
36    Table(#[from] redb::TableError),
37
38    /// redb transaction error.
39    #[error("redb transaction: {0}")]
40    Transaction(Box<redb::TransactionError>),
41
42    /// redb storage error.
43    #[error("redb storage: {0}")]
44    Storage(#[from] redb::StorageError),
45
46    /// redb commit error.
47    #[error("redb commit: {0}")]
48    Commit(#[from] redb::CommitError),
49
50    /// Failed to encode a record for on-disk storage.
51    #[error("serialize: {0}")]
52    SerializeFailed(#[source] rmp_serde::encode::Error),
53
54    /// On-disk record could not be decoded (corrupt or incompatible format).
55    #[error("deserialize: {0}")]
56    DeserializeFailed(#[source] rmp_serde::decode::Error),
57
58    /// Deserialized cert bytes failed validation.
59    #[error("invalid DaCert data: {0}")]
60    InvalidCertData(String),
61
62    /// Snapshot body exceeds the safety limit.
63    #[error("snapshot body too large: {size} bytes exceeds max {max} bytes")]
64    SnapshotBodyTooLarge {
65        /// Actual body size in bytes.
66        size: usize,
67        /// Configured maximum.
68        max: usize,
69    },
70
71    /// `header.body_len` does not match the actual body slice length.
72    #[error("snapshot body_len mismatch: header says {header_body_len}, actual {actual}")]
73    SnapshotBodyLenMismatch {
74        /// Value in the header.
75        header_body_len: u64,
76        /// Actual body slice length.
77        actual: u64,
78    },
79
80    /// A delta field exceeds the safety limit.
81    #[error("delta field `{field}` too large: {size} bytes exceeds max {max} bytes")]
82    DeltaFieldTooLarge {
83        /// Which field violated the limit.
84        field: &'static str,
85        /// Actual size in bytes.
86        size: usize,
87        /// Configured maximum.
88        max: usize,
89    },
90
91    /// `fetch_range` was called with a window wider than the configured limit.
92    #[error("fetch_range too large: requested {requested} entries exceeds max {max}")]
93    FetchRangeTooLarge {
94        /// Number of entries the caller asked for (`to_seq - from_seq`).
95        requested: u64,
96        /// Configured maximum window width.
97        max: u64,
98    },
99}
100
101impl From<redb::TransactionError> for BootnodeError {
102    fn from(e: redb::TransactionError) -> Self {
103        Self::Transaction(Box::new(e))
104    }
105}
106
107impl From<rmp_serde::encode::Error> for BootnodeError {
108    fn from(e: rmp_serde::encode::Error) -> Self {
109        Self::SerializeFailed(e)
110    }
111}
112
113impl From<rmp_serde::decode::Error> for BootnodeError {
114    fn from(e: rmp_serde::decode::Error) -> Self {
115        Self::DeserializeFailed(e)
116    }
117}