massa_protocol_exports/
error.rs

1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3use displaydoc::Display;
4use massa_models::error::ModelsError;
5use massa_pos_exports::PosError;
6use massa_versioning::versioning_factory::FactoryError;
7use std::net::IpAddr;
8use thiserror::Error;
9
10/// protocol error
11#[non_exhaustive]
12#[derive(Display, Error, Debug)]
13pub enum ProtocolError {
14    /// Wrong signature
15    WrongSignature,
16    /// Protocol error: {0}
17    GeneralProtocolError(String),
18    /// Invalid block: {0}
19    InvalidBlock(String),
20    /// An error occurred during channel communication: {0}
21    ChannelError(String),
22    /// Error during network connection: `{0:?}`
23    PeerConnectionError(NetworkConnectionErrorType),
24    /// The ip: `{0}` address is not valid
25    InvalidIpError(IpAddr),
26    /// IO error: {0}
27    IOError(#[from] std::io::Error),
28    /// Serde error: {0}
29    SerdeError(#[from] serde_json::Error),
30    /// The network controller should not drop a node command sender before shutting down the node.
31    UnexpectedNodeCommandChannelClosure,
32    /// The writer of a node should not drop its event sender before sending a `clean_exit` message.
33    UnexpectedWriterClosure,
34    /// Time error: {0}
35    TimeError(#[from] massa_time::TimeError),
36    /// Missing peers
37    MissingPeersError,
38    /// Models error: {0}
39    ModelsError(#[from] ModelsError),
40    /// Send error: {0}
41    SendError(String),
42    /// Peer disconnected : {0}
43    PeerDisconnected(String),
44    /// Container inconsistency error: {0}
45    ContainerInconsistencyError(String),
46    /// Invalid operation error: {0}
47    InvalidOperationError(String),
48    /// Listener error: {0}
49    ListenerError(String),
50    /// Incompatible network version: local current is {local} received is {received}
51    IncompatibleNetworkVersion {
52        /// local current version
53        local: u32,
54        /// received current network version from incoming header
55        received: u32,
56    },
57    /// Invalid announced network version
58    OutdatedAnnouncedNetworkVersion {
59        /// local current version
60        local: u32,
61        /// received announced network version
62        announced_received: u32,
63    },
64    /// Versioned factory error: {0}
65    FactoryError(#[from] FactoryError),
66    /// PoS error: {0}
67    PosError(#[from] PosError),
68}
69
70#[derive(Debug)]
71pub enum NetworkConnectionErrorType {
72    CloseConnectionWithNoConnectionToClose(IpAddr),
73    PeerInfoNotFoundError(IpAddr),
74    ToManyConnectionAttempt(IpAddr),
75    ToManyConnectionFailure(IpAddr),
76}