snarkos_errors/network/
server.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    network::{message::MessageError, ConnectError, HandshakeError, PingProtocolError, SendError},
19    objects::{BlockError, TransactionError},
20    storage::StorageError,
21};
22
23#[derive(Debug, Error)]
24pub enum ServerError {
25    #[error("{}", _0)]
26    BlockError(BlockError),
27
28    #[error("{}: {}", _0, _1)]
29    Crate(&'static str, String),
30
31    #[error("{}", _0)]
32    ConnectError(ConnectError),
33
34    #[error("{}", _0)]
35    HandshakeError(HandshakeError),
36
37    #[error("{}", _0)]
38    Message(String),
39
40    #[error("{}", _0)]
41    MessageError(MessageError),
42
43    #[error("{}", _0)]
44    PingProtocolError(PingProtocolError),
45
46    #[error("{}", _0)]
47    SendError(SendError),
48
49    #[error("{}", _0)]
50    StorageError(StorageError),
51
52    #[error("{}", _0)]
53    TransactionError(TransactionError),
54}
55
56impl From<BlockError> for ServerError {
57    fn from(error: BlockError) -> Self {
58        ServerError::BlockError(error)
59    }
60}
61
62impl From<ConnectError> for ServerError {
63    fn from(error: ConnectError) -> Self {
64        ServerError::ConnectError(error)
65    }
66}
67
68impl From<HandshakeError> for ServerError {
69    fn from(error: HandshakeError) -> Self {
70        ServerError::HandshakeError(error)
71    }
72}
73
74impl From<MessageError> for ServerError {
75    fn from(error: MessageError) -> Self {
76        ServerError::MessageError(error)
77    }
78}
79
80impl From<PingProtocolError> for ServerError {
81    fn from(error: PingProtocolError) -> Self {
82        ServerError::PingProtocolError(error)
83    }
84}
85
86impl From<SendError> for ServerError {
87    fn from(error: SendError) -> Self {
88        ServerError::SendError(error)
89    }
90}
91
92impl From<StorageError> for ServerError {
93    fn from(error: StorageError) -> Self {
94        ServerError::StorageError(error)
95    }
96}
97
98impl From<TransactionError> for ServerError {
99    fn from(error: TransactionError) -> Self {
100        ServerError::TransactionError(error)
101    }
102}
103
104impl From<std::io::Error> for ServerError {
105    fn from(error: std::io::Error) -> Self {
106        ServerError::Crate("std::io", format!("{:?}", error))
107    }
108}
109
110impl From<std::net::AddrParseError> for ServerError {
111    fn from(error: std::net::AddrParseError) -> Self {
112        ServerError::Crate("std::net::AddrParseError", format!("{:?}", error))
113    }
114}
115
116impl From<bincode::Error> for ServerError {
117    fn from(error: bincode::Error) -> Self {
118        ServerError::Crate("bincode", format!("{:?}", error))
119    }
120}