massa_bootstrap/
error.rs

1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3use std::io::ErrorKind;
4
5use crate::messages::{BootstrapClientMessage, BootstrapServerMessage};
6use displaydoc::Display;
7use massa_consensus_exports::error::ConsensusError;
8use massa_final_state::FinalStateError;
9use massa_hash::MassaHashError;
10use massa_pos_exports::PosError;
11use massa_protocol_exports::ProtocolError;
12use massa_serialization::SerializeError;
13use massa_time::TimeError;
14use thiserror::Error;
15
16#[non_exhaustive]
17#[derive(Display, Error, Debug)]
18/// Encapsulates the various failure contexts for the bootstrap process, both client and server side
19pub enum BootstrapError {
20    /// Bootstrap IO error: {0}
21    IoError(std::io::Error),
22    /// Bootstrap process timeout: {0}
23    TimedOut(std::io::Error),
24    /// general bootstrap error: {0}
25    GeneralError(String),
26    /// deserialization error: {0}
27    DeserializeError(String),
28    /// serialization error: {0}
29    SerializationError(String),
30    /// models error: {0}
31    ModelsError(#[from] massa_models::error::ModelsError),
32    /// serialize error: {0}
33    SerializeError(#[from] SerializeError),
34    /// unexpected message received from server: {0:?}
35    UnexpectedServerMessage(BootstrapServerMessage),
36    /// unexpected message received from client: {0:?}
37    UnexpectedClientMessage(Box<BootstrapClientMessage>),
38    /// connection with bootstrap node dropped
39    UnexpectedConnectionDrop,
40    /// `massa_hash` error: {0}
41    MassaHashError(#[from] MassaHashError),
42    /// `massa_consensus` error: {0}
43    MassaConsensusError(#[from] ConsensusError),
44    /// `massa_signature` error {0}
45    MassaSignatureError(#[from] massa_signature::MassaSignatureError),
46    /// time error: {0}
47    TimeError(#[from] TimeError),
48    /// protocol error: {0}
49    ProtocolError(#[from] ProtocolError),
50    /// final state error: {0}
51    FinalStateError(#[from] FinalStateError),
52    /// Proof-of-Stake error: {0}
53    PoSError(#[from] PosError),
54    /// missing keypair file
55    MissingKeyError,
56    /// incompatible version: {0}
57    IncompatibleVersionError(String),
58    /// Received error: {0}
59    ReceivedError(String),
60    /// clock error: {0}
61    ClockError(String),
62    /// fail to init the list from file : {0}
63    InitListError(String),
64    /// IP {0} is blacklisted
65    BlackListed(String),
66    /// IP {0} is not in the whitelist
67    WhiteListed(String),
68    /// The bootstrap process ended prematurely - e.g. too much time elapsed
69    Interrupted(String),
70}
71
72/// # Platform-specific behavior
73///
74/// Platforms may return a different error code whenever a read times out as
75/// a result of setting this option. For example Unix typically returns an
76/// error of the kind [`ErrorKind::WouldBlock`], but Windows may return [`ErrorKind::TimedOut`].)
77impl From<std::io::Error> for BootstrapError {
78    fn from(e: std::io::Error) -> Self {
79        if e.kind() == ErrorKind::TimedOut || e.kind() == ErrorKind::WouldBlock {
80            BootstrapError::TimedOut(e)
81        } else {
82            BootstrapError::IoError(e)
83        }
84    }
85}