Skip to main content

elura_netcode/
error.rs

1use std::fmt;
2
3/// Result returned by netcode primitives.
4pub type NetcodeResult<T> = std::result::Result<T, NetcodeError>;
5
6/// Configuration, timing, or input validation failure.
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum NetcodeError {
10    /// A configured limit cannot produce a bounded state machine.
11    InvalidConfig(&'static str),
12    /// A Tick synchronization observation is internally inconsistent.
13    InvalidSample(&'static str),
14    /// An input packet or frame violates its configured bounds.
15    InvalidInput(&'static str),
16    /// Unacknowledged input filled the sender's bounded history.
17    InputHistoryFull,
18    /// The local input sequence can no longer be incremented.
19    SequenceExhausted,
20    /// A peer acknowledged an input sequence that was never issued.
21    InvalidAcknowledgement,
22    /// Unconfirmed prediction frames filled the bounded client history.
23    PredictionHistoryFull,
24    /// One authoritative correction would replay more inputs than configured.
25    ReplayLimitExceeded,
26    /// A remote interpolation sample was requested before any state arrived.
27    InterpolationBufferEmpty,
28    /// Pending predicted entities filled the bounded matcher.
29    PredictedEntityLimit,
30}
31
32impl fmt::Display for NetcodeError {
33    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            Self::InvalidConfig(message) => write!(formatter, "invalid netcode config: {message}"),
36            Self::InvalidSample(message) => write!(formatter, "invalid Tick sample: {message}"),
37            Self::InvalidInput(message) => write!(formatter, "invalid input: {message}"),
38            Self::InputHistoryFull => formatter.write_str("unacknowledged input history is full"),
39            Self::SequenceExhausted => formatter.write_str("input sequence is exhausted"),
40            Self::InvalidAcknowledgement => {
41                formatter.write_str("peer acknowledged an input sequence that was never issued")
42            }
43            Self::PredictionHistoryFull => {
44                formatter.write_str("unconfirmed prediction history is full")
45            }
46            Self::ReplayLimitExceeded => formatter.write_str("prediction replay limit exceeded"),
47            Self::InterpolationBufferEmpty => {
48                formatter.write_str("remote interpolation buffer is empty")
49            }
50            Self::PredictedEntityLimit => {
51                formatter.write_str("pending predicted entity limit exceeded")
52            }
53        }
54    }
55}
56
57impl std::error::Error for NetcodeError {}