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    /// Other state manager error
22    #[error("{0}")]
23    Other(String),
24}
25
26impl Error {
27    pub fn state(e: impl Display) -> Self {
28        Self::State(e.to_string())
29    }
30
31    pub fn other(e: impl Display) -> Self {
32        Self::Other(e.to_string())
33    }
34}
35
36impl From<String> for Error {
37    fn from(e: String) -> Self {
38        Error::Other(e)
39    }
40}
41
42impl From<anyhow::Error> for Error {
43    fn from(e: anyhow::Error) -> Self {
44        Error::other(format!("{e:#}"))
45    }
46}
47
48impl From<JoinError> for Error {
49    fn from(e: JoinError) -> Self {
50        Error::Other(format!("failed joining on tokio task: {e}"))
51    }
52}