ex3_node_error/
internal.rs1use std::fmt;
2
3use thiserror::Error;
4
5use crate::{
6 def_error_base_on_kind, impl_error_conversion_with_adaptor, impl_error_conversion_with_kind,
7};
8
9#[derive(Error, Debug, Clone, Copy)]
11#[error("no reason is provided")]
12pub struct SilentError;
13
14#[derive(Error, Debug, Clone)]
16#[error("{0}")]
17pub struct OtherError(String);
18
19#[derive(Debug, PartialEq, Eq, Clone, Copy)]
20pub enum InternalErrorKind {
21 DataCorrupted,
23
24 Database,
26
27 System,
29
30 Config,
32
33 Canister,
35
36 Other,
38}
39
40def_error_base_on_kind!(InternalError, InternalErrorKind, "Internal error.");
41impl_error_conversion_with_kind!(InternalError, crate::ErrorKind::Internal, crate::Error);
42
43impl_error_conversion_with_kind!(OtherError, InternalErrorKind::Other, InternalError);
44impl_error_conversion_with_adaptor!(OtherError, InternalError, crate::Error);
45
46impl OtherError {
47 pub fn new<T>(reason: T) -> Self
49 where
50 T: fmt::Display,
51 {
52 Self(reason.to_string())
53 }
54}