forest/chain/store/
errors.rs1use std::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;
11
12#[derive(Debug, Error)]
14pub enum Error {
15 #[error("Invalid tipset: {0}")]
17 UndefinedKey(String),
18 #[error("{0} not found")]
20 NotFound(String),
21 #[error(transparent)]
23 Blockchain(#[from] CreateTipsetError),
24 #[error("{0}")]
26 Encoding(String),
27 #[error(transparent)]
29 Cid(#[from] CidErr),
30 #[error("State error: {0}")]
32 State(String),
33 #[error("{0}")]
35 Other(String),
36}
37
38impl From<EncErr> for Error {
39 fn from(e: EncErr) -> Error {
40 Error::Encoding(e.to_string())
41 }
42}
43
44impl From<AmtErr> for Error {
45 fn from(e: AmtErr) -> Error {
46 Error::State(e.to_string())
47 }
48}
49
50impl From<String> for Error {
51 fn from(e: String) -> Self {
52 Error::Other(e)
53 }
54}
55
56impl From<anyhow::Error> for Error {
57 fn from(e: anyhow::Error) -> Self {
58 Error::Other(e.to_string())
59 }
60}
61
62impl From<std::io::Error> for Error {
63 fn from(e: std::io::Error) -> Self {
64 Error::Other(e.to_string())
65 }
66}
67
68impl<T> From<flume::SendError<T>> for Error {
69 fn from(e: flume::SendError<T>) -> Self {
70 Error::Other(e.to_string())
71 }
72}
73
74impl Error {
75 pub fn state(msg: impl std::fmt::Display) -> Self {
76 Self::State(msg.to_string())
77 }
78}