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

  1. Check the packet's declared length vs. bytes actually received before deserializing
  2. Confirm the field order matches the protocol specification
  3. Validate the payload is complete before calling read_slice
  4. 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

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


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)