forest/chain/store/
errors.rs1use std::{borrow::Cow, fmt::Debug};
5
6use crate::blocks::CreateTipsetError;
7use cid::Error as CidErr;
8use fil_actors_shared::fvm_ipld_amt::Error as AmtErr;
9use fvm_ipld_encoding::Error as EncErr;
10use thiserror::Error;
11use tokio::task::JoinError;
12
13#[derive(Debug, Error)]
15pub enum Error {
16 #[error("Invalid tipset: {0}")]
18 UndefinedKey(String),
19 #[error("{0} not found")]
21 NotFound(Cow<'static, str>),
22 #[error(transparent)]
24 Blockchain(#[from] CreateTipsetError),
25 #[error("{0}")]
27 Encoding(String),
28 #[error(transparent)]
30 Cid(#[from] CidErr),
31 #[error("State error: {0}")]
33 State(Cow<'static, str>),
34 #[error("null round at epoch {0}")]
38 NullRound(crate::shim::clock::ChainEpoch),
39 #[error("{0}")]
41 Other(String),
42}
43
44impl From<EncErr> for Error {
45 fn from(e: EncErr) -> Error {
46 Error::Encoding(e.to_string())
47 }
48}
49
50impl From<AmtErr> for Error {
51 fn from(e: AmtErr) -> Error {
52 Error::state(e.to_string())
53 }
54}
55
56impl From<String> for Error {
57 fn from(e: String) -> Self {
58 Error::Other(e)
59 }
60}
61
62impl From<anyhow::Error> for Error {
63 fn from(e: anyhow::Error) -> Self {
64 Error::Other(format!("{e:#}"))
65 }
66}
67
68impl From<std::io::Error> for Error {
69 fn from(e: std::io::Error) -> Self {
70 Error::Other(e.to_string())
71 }
72}
73
74impl<T> From<flume::SendError<T>> for Error {
75 fn from(e: flume::SendError<T>) -> Self {
76 Error::Other(e.to_string())
77 }
78}
79
80impl From<JoinError> for Error {
81 fn from(e: JoinError) -> Self {
82 Error::Other(format!("failed joining on tokio task: {e}"))
83 }
84}
85
86impl Error {
87 pub fn state(msg: impl Into<Cow<'static, str>>) -> Self {
88 Self::State(msg.into())
89 }
90}