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 thiserror::Error;
7use tokio::task::JoinError;
8
9/// State manager error
10#[derive(Debug, PartialEq, Error)]
11pub enum Error {
12    /// Error originating from state
13    #[error("{0}")]
14    State(String),
15    /// Refusing explicit call due to an expensive state migration at the requested epoch.
16    #[error("refusing explicit call due to state fork at epoch")]
17    ExpensiveFork,
18    /// Other state manager error
19    #[error("{0}")]
20    Other(String),
21}
22
23impl Error {
24    pub fn state(e: impl Display) -> Self {
25        Self::State(e.to_string())
26    }
27
28    pub fn other(e: impl Display) -> Self {
29        Self::Other(e.to_string())
30    }
31}
32
33impl From<String> for Error {
34    fn from(e: String) -> Self {
35        Error::Other(e)
36    }
37}
38
39impl From<anyhow::Error> for Error {
40    fn from(e: anyhow::Error) -> Self {
41        Error::other(format!("{e:#}"))
42    }
43}
44
45impl From<JoinError> for Error {
46    fn from(e: JoinError) -> Self {
47        Error::Other(format!("failed joining on tokio task: {e}"))
48    }
49}