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