forest/state_manager/
errors.rs1use std::fmt::{Debug, Display};
5
6use crate::shim::clock::ChainEpoch;
7use thiserror::Error;
8use tokio::task::JoinError;
9
10#[derive(Debug, PartialEq, Error)]
12pub enum Error {
13 #[error("{0}")]
15 State(String),
16 #[error(
18 "required historical state unavailable: refusing explicit call due to state fork at epoch {epoch}"
19 )]
20 ExpensiveFork { epoch: ChainEpoch },
21 #[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}