1use 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)]
18pub enum BootstrapError {
20 IoError(std::io::Error),
22 TimedOut(std::io::Error),
24 GeneralError(String),
26 DeserializeError(String),
28 SerializationError(String),
30 ModelsError(#[from] massa_models::error::ModelsError),
32 SerializeError(#[from] SerializeError),
34 UnexpectedServerMessage(BootstrapServerMessage),
36 UnexpectedClientMessage(Box<BootstrapClientMessage>),
38 UnexpectedConnectionDrop,
40 MassaHashError(#[from] MassaHashError),
42 MassaConsensusError(#[from] ConsensusError),
44 MassaSignatureError(#[from] massa_signature::MassaSignatureError),
46 TimeError(#[from] TimeError),
48 ProtocolError(#[from] ProtocolError),
50 FinalStateError(#[from] FinalStateError),
52 PoSError(#[from] PosError),
54 MissingKeyError,
56 IncompatibleVersionError(String),
58 ReceivedError(String),
60 ClockError(String),
62 InitListError(String),
64 BlackListed(String),
66 WhiteListed(String),
68 Interrupted(String),
70}
71
72impl 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}