ex3_canister_error/
lib.rs

1use derive_more::Display;
2
3pub use common::{CommonError, CommonErrorKind, OtherError, SilentError};
4
5pub mod common;
6pub mod prelude;
7pub mod util;
8
9pub const SECOND_LEVEL_ERROR_CODE_INTERVAL: u32 = 1000u32;
10
11pub trait ErrorCode {
12    fn error_code(&self) -> u32;
13}
14
15/// A list specifying categories of main node error.
16#[derive(Debug, Clone, Copy, Eq, PartialEq, Display)]
17pub enum ErrorKind {
18    Common,
19    AssetVault,
20    BalanceSnapshot,
21    BalanceSnapshotFactory,
22    Blockchain,
23    CoreRegistry,
24    DepositDetector,
25    SecretVault,
26    SecretVaultFactory,
27    WalletRegistry,
28    WalletRegistryFactory,
29    AssetCreatorDetector,
30}
31
32impl ErrorCode for ErrorKind {
33    fn error_code(&self) -> u32 {
34        match self {
35            Self::Common => 10000,
36            Self::AssetVault => 20000,
37            Self::BalanceSnapshot => 30000,
38            Self::BalanceSnapshotFactory => 40000,
39            Self::Blockchain => 50000,
40            Self::CoreRegistry => 60000,
41            Self::DepositDetector => 70000,
42            Self::SecretVault => 80000,
43            Self::SecretVaultFactory => 90000,
44            Self::WalletRegistry => 100000,
45            Self::WalletRegistryFactory => 110000,
46            Self::AssetCreatorDetector => 120000,
47        }
48    }
49}