snarkos_errors/node/
node.rs

1// Copyright (C) 2019-2020 Aleo Systems Inc.
2// This file is part of the snarkOS library.
3
4// The snarkOS library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The snarkOS library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::{
18    algorithms::CRHError,
19    consensus::ConsensusError,
20    network::ServerError,
21    node::CliError,
22    objects::AccountError,
23    storage::StorageError,
24};
25
26#[derive(Debug, Error)]
27pub enum NodeError {
28    #[error("{}", _0)]
29    AccountError(AccountError),
30
31    #[error("{}", _0)]
32    CLIError(CliError),
33
34    #[error("{}", _0)]
35    CRHError(CRHError),
36
37    #[error("{}", _0)]
38    ConsensusError(ConsensusError),
39
40    #[error("{}: {}", _0, _1)]
41    Crate(&'static str, String),
42
43    #[error("{}", _0)]
44    Message(String),
45
46    #[error("{}", _0)]
47    ServerError(ServerError),
48
49    #[error("{}", _0)]
50    StorageError(StorageError),
51}
52
53impl From<AccountError> for NodeError {
54    fn from(error: AccountError) -> Self {
55        NodeError::AccountError(error)
56    }
57}
58
59impl From<CliError> for NodeError {
60    fn from(error: CliError) -> Self {
61        NodeError::CLIError(error)
62    }
63}
64
65impl From<CRHError> for NodeError {
66    fn from(error: CRHError) -> Self {
67        NodeError::CRHError(error)
68    }
69}
70
71impl From<ConsensusError> for NodeError {
72    fn from(error: ConsensusError) -> Self {
73        NodeError::ConsensusError(error)
74    }
75}
76
77impl From<hex::FromHexError> for NodeError {
78    fn from(error: hex::FromHexError) -> Self {
79        NodeError::Crate("hex", format!("{:?}", error))
80    }
81}
82
83impl From<ServerError> for NodeError {
84    fn from(error: ServerError) -> Self {
85        NodeError::ServerError(error)
86    }
87}
88
89impl From<StorageError> for NodeError {
90    fn from(error: StorageError) -> Self {
91        NodeError::StorageError(error)
92    }
93}
94
95impl From<std::io::Error> for NodeError {
96    fn from(error: std::io::Error) -> Self {
97        NodeError::Crate("std::io", format!("{:?}", error))
98    }
99}
100
101impl From<std::net::AddrParseError> for NodeError {
102    fn from(error: std::net::AddrParseError) -> Self {
103        NodeError::Crate("std::net::AddrParseError", format!("{:?}", error))
104    }
105}
106
107impl From<std::boxed::Box<dyn std::error::Error>> for NodeError {
108    fn from(error: std::boxed::Box<dyn std::error::Error>) -> Self {
109        NodeError::Crate("std::boxed::Box", format!("{:?}", error))
110    }
111}