chore: rewrite all error messages for consistency (#5176)

Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com>
This commit is contained in:
DaniPopes
2023-10-25 22:12:03 +02:00
committed by GitHub
parent 1c0373b322
commit e05dba69ce
73 changed files with 649 additions and 599 deletions

View File

@ -50,28 +50,27 @@ pub enum DisconnectReason {
impl Display for DisconnectReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = match self {
DisconnectReason::DisconnectRequested => "Disconnect requested",
DisconnectReason::DisconnectRequested => "disconnect requested",
DisconnectReason::TcpSubsystemError => "TCP sub-system error",
DisconnectReason::ProtocolBreach => {
"Breach of protocol, e.g. a malformed message, bad RLP, ..."
"breach of protocol, e.g. a malformed message, bad RLP, etc."
}
DisconnectReason::UselessPeer => "Useless peer",
DisconnectReason::TooManyPeers => "Too many peers",
DisconnectReason::AlreadyConnected => "Already connected",
DisconnectReason::IncompatibleP2PProtocolVersion => "Incompatible P2P protocol version",
DisconnectReason::UselessPeer => "useless peer",
DisconnectReason::TooManyPeers => "too many peers",
DisconnectReason::AlreadyConnected => "already connected",
DisconnectReason::IncompatibleP2PProtocolVersion => "incompatible P2P protocol version",
DisconnectReason::NullNodeIdentity => {
"Null node identity received - this is automatically invalid"
"null node identity received - this is automatically invalid"
}
DisconnectReason::ClientQuitting => "Client quitting",
DisconnectReason::UnexpectedHandshakeIdentity => "Unexpected identity in handshake",
DisconnectReason::ClientQuitting => "client quitting",
DisconnectReason::UnexpectedHandshakeIdentity => "unexpected identity in handshake",
DisconnectReason::ConnectedToSelf => {
"Identity is the same as this node (i.e. connected to itself)"
"identity is the same as this node (i.e. connected to itself)"
}
DisconnectReason::PingTimeout => "Ping timeout",
DisconnectReason::SubprotocolSpecific => "Some other reason specific to a subprotocol",
DisconnectReason::PingTimeout => "ping timeout",
DisconnectReason::SubprotocolSpecific => "some other reason specific to a subprotocol",
};
write!(f, "{message}")
f.write_str(message)
}
}

View File

@ -15,7 +15,7 @@ pub enum EthStreamError {
ParseVersionError(#[from] ParseVersionError),
#[error(transparent)]
EthHandshakeError(#[from] EthHandshakeError),
#[error("For {0:?} version, message id({1:?}) is invalid")]
#[error("message id {1:?} is invalid for version {0:?}")]
EthInvalidMessageError(EthVersion, EthMessageID),
#[error("message size ({0}) exceeds max length (10MB)")]
MessageTooBig(usize),
@ -68,12 +68,12 @@ pub enum EthHandshakeError {
NoResponse,
#[error(transparent)]
InvalidFork(#[from] ValidationError),
#[error("mismatched genesis in Status message. expected: {expected:?}, got: {got:?}")]
#[error("mismatched genesis in status message: got {got}, expected {expected}")]
MismatchedGenesis { expected: B256, got: B256 },
#[error("mismatched protocol version in Status message. expected: {expected:?}, got: {got:?}")]
#[error("mismatched protocol version in status message: got {got}, expected {expected}")]
MismatchedProtocolVersion { expected: u8, got: u8 },
#[error("mismatched chain in Status message. expected: {expected:?}, got: {got:?}")]
#[error("mismatched chain in status message: got {got}, expected {expected}")]
MismatchedChain { expected: Chain, got: Chain },
#[error("total difficulty bitlen is too large. maximum: {maximum:?}, got: {got:?}")]
#[error("total difficulty bitlen is too large: got {got}, maximum {maximum}")]
TotalDifficultyBitLenTooLarge { maximum: usize, got: usize },
}

View File

@ -70,7 +70,7 @@ pub enum P2PHandshakeError {
NoResponse,
#[error("handshake timed out")]
Timeout,
#[error("Disconnected by peer: {0}")]
#[error("disconnected by peer: {0}")]
Disconnected(DisconnectReason),
#[error("error decoding a message during handshake: {0}")]
DecodeError(#[from] alloy_rlp::Error),