ex3_node_error/
lib.rs

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