forest/chain/store/
errors.rs

1// Copyright 2019-2025 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use 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/// Chain error
13#[derive(Debug, Error)]
14pub enum Error {
15    /// Key was not found
16    #[error("Invalid tipset: {0}")]
17    UndefinedKey(String),
18    /// Key not found in database
19    #[error("{0} not found")]
20    NotFound(String),
21    /// Error originating constructing blockchain structures
22    #[error(transparent)]
23    Blockchain(#[from] CreateTipsetError),
24    /// Error originating from encoding arbitrary data
25    #[error("{0}")]
26    Encoding(String),
27    /// Error originating from Cid creation
28    #[error(transparent)]
29    Cid(#[from] CidErr),
30    /// Amt error
31    #[error("State error: {0}")]
32    State(String),
33    /// Other chain error
34    #[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}