ex3_error/
lib.rs

1use std::{error::Error as StdError, fmt, ops::Deref, sync::Arc};
2
3use derive_more::Display;
4use thiserror::Error;
5
6pub use internal::{InternalError, InternalErrorKind, OtherError, SilentError};
7
8mod internal;
9pub mod prelude;
10pub mod util;
11
12/// A wrapper around a dynamic error type.
13#[derive(Clone)]
14pub struct AnyError(Arc<anyhow::Error>);
15
16/// A list specifying categories of main node error.
17#[derive(Debug, Clone, Copy, Eq, PartialEq, Display)]
18pub enum ErrorKind {
19    Header,
20    Block,
21    Transaction,
22    Internal,
23    Crypto,
24}
25
26def_error_base_on_kind!(Error, ErrorKind, "Top-level ex3 error type.");
27
28impl<E> From<E> for AnyError
29where
30    E: StdError + Send + Sync + 'static,
31{
32    fn from(error: E) -> Self {
33        Self(Arc::new(error.into()))
34    }
35}
36
37impl Deref for AnyError {
38    type Target = Arc<anyhow::Error>;
39
40    fn deref(&self) -> &Self::Target {
41        &self.0
42    }
43}
44
45impl fmt::Display for AnyError {
46    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47        self.0.fmt(f)
48    }
49}
50
51impl fmt::Debug for AnyError {
52    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53        self.0.fmt(f)
54    }
55}