Skip to main content

eth_state_diff/
error.rs

1use std::fmt;
2
3/// Errors that can occur during delta creation or application.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Error {
6    /// The delta targets a different fork than the provided state.
7    ForkMismatch {
8        state_fork: crate::ForkName,
9        delta_fork: crate::ForkName,
10    },
11    /// A field was included in the delta that does not exist for the delta's fork.
12    InvalidFieldForFork {
13        field: &'static str,
14        fork: crate::ForkName,
15    },
16    /// The delta payload is malformed or missing expected data (e.g., corrupted zstd/rkyv).
17    MalformedDelta(String),
18}
19
20impl fmt::Display for Error {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Error::ForkMismatch {
24                state_fork,
25                delta_fork,
26            } => {
27                write!(
28                    f,
29                    "Fork mismatch: cannot apply {delta_fork:?} delta to {state_fork:?} state",
30                )
31            }
32            Error::InvalidFieldForFork { field, fork } => {
33                write!(f, "Field '{field}' is invalid for fork {fork:?}")
34            }
35            Error::MalformedDelta(msg) => {
36                write!(f, "Malformed delta payload: {msg}")
37            }
38        }
39    }
40}
41
42impl std::error::Error for Error {}