basalt_mc_protocol/error.rs
1/// Crate-level result alias.
2pub type Result<T> = std::result::Result<T, Error>;
3
4/// Errors that can occur during packet encoding, decoding, or registry dispatch.
5///
6/// This error type wraps `basalt_types::Error` for lower-level serialization
7/// failures and adds protocol-specific errors like unknown packet IDs.
8/// Higher layers (basalt-net) wrap this error in turn via `#[from]`.
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11 /// A packet ID was not recognized for the given connection state.
12 ///
13 /// This occurs when the registry receives a packet ID that doesn't
14 /// match any known packet in the current state and direction. May
15 /// indicate a protocol version mismatch, a corrupted stream, or
16 /// an unimplemented packet.
17 #[error("unknown packet ID {id:#04x} in state {state}")]
18 UnknownPacket {
19 /// The unrecognized packet ID.
20 id: i32,
21 /// The connection state where the packet was received.
22 state: &'static str,
23 },
24
25 /// A lower-level type encoding/decoding error.
26 ///
27 /// Wraps errors from basalt-types: buffer underflow, invalid data,
28 /// VarInt overflow, string length violations, UTF-8 errors, and NBT
29 /// parsing failures.
30 #[error(transparent)]
31 Type(#[from] basalt_types::Error),
32}