1use std::fmt;
2
3use derive_more::Display;
4use thiserror::Error;
5
6use crate::{
7 def_error_base_on_kind, impl_error_conversion_with_adaptor, impl_error_conversion_with_kind,
8};
9
10#[derive(Error, Debug, Clone, Copy)]
12#[error("no reason is provided")]
13pub struct SilentError;
14
15#[derive(Error, Debug, Clone)]
17#[error("{0}")]
18pub struct OtherError(String);
19
20#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
21pub enum InternalErrorKind {
22 DataCorrupted,
24
25 Database,
27
28 System,
30
31 Config,
33
34 Canister,
36
37 Other,
39}
40
41def_error_base_on_kind!(InternalError, InternalErrorKind, "Internal error.");
42impl_error_conversion_with_kind!(InternalError, crate::ErrorKind::Internal, crate::Error);
43
44impl_error_conversion_with_kind!(OtherError, InternalErrorKind::Other, InternalError);
45impl_error_conversion_with_adaptor!(OtherError, InternalError, crate::Error);
46
47impl OtherError {
48 pub fn new<T>(reason: T) -> Self
50 where
51 T: fmt::Display,
52 {
53 Self(reason.to_string())
54 }
55}