Skip to main content

nodedb_cluster/wire_version/
error.rs

1// SPDX-License-Identifier: BUSL-1.1
2
3//! Wire-version error types.
4
5use thiserror::Error;
6
7use super::types::WireVersion;
8
9/// Errors arising from wire-version negotiation or versioned decode.
10#[derive(Debug, Error)]
11pub enum WireVersionError {
12    /// A peer sent a message whose version field is outside the range this
13    /// node supports. The connection must be closed; continuing would risk
14    /// silent misinterpretation of the payload.
15    #[error(
16        "unsupported wire version {peer_version} from peer \
17         (supported: {supported_min}..={supported_max})"
18    )]
19    UnsupportedVersion {
20        peer_version: WireVersion,
21        supported_min: WireVersion,
22        supported_max: WireVersion,
23    },
24
25    /// The raw bytes could not be decoded as either a versioned envelope or
26    /// a raw v1 inner type.
27    #[error("wire decode failure: {0}")]
28    DecodeFailure(String),
29
30    /// `negotiate` was called with disjoint `VersionRange` sets — no
31    /// protocol version is mutually acceptable.
32    #[error(
33        "version negotiation failed: local range {local_min}..={local_max} \
34         does not overlap remote range {remote_min}..={remote_max}"
35    )]
36    NegotiationFailed {
37        local_min: WireVersion,
38        local_max: WireVersion,
39        remote_min: WireVersion,
40        remote_max: WireVersion,
41    },
42}
43
44impl From<WireVersionError> for crate::error::ClusterError {
45    fn from(e: WireVersionError) -> Self {
46        crate::error::ClusterError::Codec {
47            detail: e.to_string(),
48        }
49    }
50}