Skip to main content

ozzy_replication/wire/
error.rs

1//! Structural wire failures.
2
3use ozzy_proto::EnvelopeError;
4use ozzy_proto::layout::LayoutError;
5
6use crate::ReplicationError;
7use crate::flow::FlowError;
8
9/// Structural wire failure. No rejection changes replica or journal state.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
11pub enum WireError {
12    /// Invalid receipt metadata or mismatched local receive incarnation.
13    #[error(transparent)]
14    Flow(#[from] FlowError),
15    /// Response does not match the live source, request, range, or response bound.
16    #[error("replica history response does not match the outstanding request")]
17    Transfer,
18    /// Invalid election view, frozen generation, or accepted/commit relationship.
19    #[error("invalid replica election history descriptor")]
20    History,
21    /// A batch/request is empty, too large, or exceeds an operation/frame work bound.
22    #[error("replica command exceeds operation or byte limits")]
23    Limit,
24    /// Unsupported canonical operation kind.
25    #[error("unsupported replica operation kind {0}")]
26    OperationKind(u16),
27    /// Canonical envelope does not continue the announced scope/hash chain.
28    #[error("replica canonical operation chain mismatch")]
29    Chain,
30    /// Body or envelope digest does not match the received canonical bytes.
31    #[error("replica canonical operation digest mismatch")]
32    Digest,
33    /// Invalid native envelope or directional frame bound.
34    #[error(transparent)]
35    Envelope(#[from] EnvelopeError),
36    /// Invalid configured voter supplied to the binding.
37    #[error(transparent)]
38    Configuration(#[from] ReplicationError),
39    /// Sender, embedded voter, or session does not match authenticated binding.
40    #[error("replica peer or session mismatch")]
41    Peer,
42    /// Group/configuration epoch/digest does not match the configured group.
43    #[error("replica configuration scope mismatch")]
44    Scope,
45    /// Invalid genesis/digest pairing or unrepresentable successor operation.
46    #[error("invalid replica log prefix")]
47    Prefix,
48    /// A control command cannot carry payload bytes.
49    #[error("unexpected replica payload")]
50    Payload,
51    /// Truncated fields or extra metadata.
52    #[error("replica metadata length mismatch")]
53    Length,
54    /// Output storage cannot hold the complete encoded message.
55    #[error("replica encoding buffer too small")]
56    Capacity,
57    /// Command correlation/response flag does not match its exchange family.
58    #[error("invalid replica command correlation")]
59    Correlation,
60    /// Opcode does not have an implemented replica codec.
61    #[error("unsupported replica command")]
62    UnsupportedCommand,
63}
64
65impl From<LayoutError> for WireError {
66    fn from(error: LayoutError) -> Self {
67        match error {
68            LayoutError::Truncated { .. } | LayoutError::Trailing(_) => Self::Length,
69            LayoutError::Overflow { .. } => Self::Capacity,
70        }
71    }
72}