zcash_client_backend/data_api/chain/
error.rs1use std::error;
4use std::fmt::{self, Debug, Display};
5
6use crate::scanning::ScanError;
7
8#[derive(Debug)]
10#[non_exhaustive]
11pub enum Error<WalletError, BlockSourceError> {
12 Wallet(WalletError),
14
15 BlockSource(BlockSourceError),
18
19 Scan(ScanError),
23}
24
25impl<WE: fmt::Display, BE: fmt::Display> fmt::Display for Error<WE, BE> {
26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 match &self {
28 Error::Wallet(e) => {
29 write!(
30 f,
31 "The underlying datasource produced the following error: {e}"
32 )
33 }
34 Error::BlockSource(e) => {
35 write!(
36 f,
37 "The underlying block store produced the following error: {e}"
38 )
39 }
40 Error::Scan(e) => {
41 write!(f, "Scanning produced the following error: {e}")
42 }
43 }
44 }
45}
46
47impl<WE, BE> error::Error for Error<WE, BE>
48where
49 WE: Debug + Display + error::Error + 'static,
50 BE: Debug + Display + error::Error + 'static,
51{
52 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
53 match &self {
54 Error::Wallet(e) => Some(e),
55 Error::BlockSource(e) => Some(e),
56 _ => None,
57 }
58 }
59}
60
61impl<WE, BSE> From<ScanError> for Error<WE, BSE> {
62 fn from(e: ScanError) -> Self {
63 Error::Scan(e)
64 }
65}