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("{0}")]
36 Other(String),
37}
38
39impl From<EncErr> for Error {
40 fn from(e: EncErr) -> Error {
41 Error::Encoding(e.to_string())
42 }
43}
44
45impl From<AmtErr> for Error {
46 fn from(e: AmtErr) -> Error {
47 Error::state(e.to_string())
48 }
49}
50
51impl From<String> for Error {
52 fn from(e: String) -> Self {
53 Error::Other(e)
54 }
55}
56
57impl From<anyhow::Error> for Error {
58 fn from(e: anyhow::Error) -> Self {
59 Error::Other(format!("{e:#}"))
60 }
61}
62
63impl From<std::io::Error> for Error {
64 fn from(e: std::io::Error) -> Self {
65 Error::Other(e.to_string())
66 }
67}
68
69impl<T> From<flume::SendError<T>> for Error {
70 fn from(e: flume::SendError<T>) -> Self {
71 Error::Other(e.to_string())
72 }
73}
74
75impl From<JoinError> for Error {
76 fn from(e: JoinError) -> Self {
77 Error::Other(format!("failed joining on tokio task: {e}"))
78 }
79}
80
81impl Error {
82 pub fn state(msg: impl Into<Cow<'static, str>>) -> Self {
83 Self::State(msg.into())
84 }
85}