Pumpkin-MC/Pumpkin · error
expected bool byte
Error message
expected bool byte
What it means
Thrown by `PacketReadSlice for bool` when the buffer is empty, i.e. there is no byte left to interpret as a boolean. It signals premature end of the packet payload during slice-based deserialization. The ErrorKind is UnexpectedEof.
Solutions
- Check the packet's declared length vs. bytes actually received before deserializing
- Confirm the field order matches the protocol specification
- Validate the payload is complete before calling read_slice
- Handle the error and drop the malformed packet
Example fix
// before
let keep_alive: bool = bool::read_slice(&mut buf)?; // may hit empty buf
// after
if buf.is_empty() {
log::warn!("packet too short for bool field");
return Err(PacketError::Truncated);
}
let keep_alive = bool::read_slice(&mut buf)?; Defensive patterns
Strategy: try-catch
Validate before calling
if buf.is_empty() { return Err(PacketError::Truncated); } Try / catch
match bool::read_slice(&mut buf) {
Ok(b) => b,
Err(e) if e.kind() == ErrorKind::UnexpectedEof => return Err(PacketError::Truncated),
Err(e) => return Err(e.into()),
} Prevention
- Validate the packet's declared length before deserializing fields
- Keep struct field order exactly matching the wire layout
- Use slice-based readers so EOF surfaces instead of panicking
When it happens
Trigger: Calling bool::read_slice on an exhausted/short buffer — e.g. the packet body ended earlier than the struct layout expects.
Common situations: Truncated packet from a malformed sender; struct field order mismatch with the actual wire layout; packet cut short by network issues before full read.
Related errors
- expected i16
- expected i32
- expected u8
- durability correction must fit in an i16
- Failed to serialize packet
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/18485198fdaa0a52.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-protocol/src/serial/deserializer.rs:269
}
}
impl<T: PacketRead> PacketRead for Option<T> {
fn read<R: Read>(reader: &mut R) -> Result<Self, Error> {
bool::read(reader)?.then(|| T::read(reader)).transpose()
}
}
impl PacketRead for Cow<'_, str> {
fn read<R: Read>(reader: &mut R) -> Result<Self, Error> {
Ok(Self::Owned(String::read(reader)?))
}
}
impl<'a> PacketReadSlice<'a> for bool {
fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {
if buf.is_empty() {
return Err(Error::new(ErrorKind::UnexpectedEof, "expected bool byte"));
}
let b = buf[0];
*buf = &buf[1..];
Ok(b != 0)
}
}
impl<'a> PacketReadSlice<'a> for u8 {
fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {
if buf.is_empty() {
return Err(Error::new(ErrorKind::UnexpectedEof, "expected u8"));
}
let b = buf[0];
*buf = &buf[1..];
Ok(b)
}
}
View on GitHub (pinned to 8d4639e25a)