Skip to main content

forest/state_manager/
errors.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use std::fmt::{Debug, Display};
5
6use crate::shim::clock::ChainEpoch;
7use thiserror::Error;
8use tokio::task::JoinError;
9
10/// State manager error
11#[derive(Debug, PartialEq, Error)]
12pub enum Error {
13    /// Error originating from state
14    #[error("{0}")]
15    State(String),
16    /// Refusing explicit call due to an expensive state migration at the requested epoch.
17    #[error(
18        "required historical state unavailable: refusing explicit call due to state fork at epoch {epoch}"
19    )]
20    ExpensiveFork { epoch: ChainEpoch },
21    /// The sender doesn't exist on chain, or is not a valid sender type.
22    /// Control flow only: callers use it to retry with skip-sender-validation.
23    #[error("{0}: sender validation failed")]
24    SenderValidationFailed(String),
25    /// Other state manager error
26    #[error("{0}")]
27    Other(String),
28}
29
30impl Error {
31    pub fn state(e: impl Display) -> Self {
32        Self::State(e.to_string())
33    }
34
35    pub fn other(e: impl Display) -> Self {
36        Self::Other(e.to_string())
37    }
38}
39
40impl From<String> for Error {
41    fn from(e: String) -> Self {
42        Error::Other(e)
43    }
44}
45
46impl From<anyhow::Error> for Error {
47    fn from(e: anyhow::Error) -> Self {
48        Error::other(format!("{e:#}"))
49    }
50}
51
52impl From<JoinError> for Error {
53    fn from(e: JoinError) -> Self {
54        Error::Other(format!("failed joining on tokio task: {e}"))
55    }
56}