forest/state_manager/
errors.rs

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