Pumpkin-MC/Pumpkin · error · ReadingError

{0}

Error message

{0}

What it means

ReadingError::Message(String) is the generic catch-all variant of the reading error enum, also used as the serde::de::Error::custom implementation. Any deserialization failure with a free-form message (e.g. an invalid VarInt, a value that violates field invariants, enum discriminant mismatch) surfaces as this variant carrying the message text.

Solutions

  1. Read the embedded message — it names the field or invariant that failed.
  2. Capture the raw packet bytes for the failing stream to debug what the peer sent.
  3. Fix the sender to produce values within the protocol's constraints.
  4. Update the library if the peer uses a newer protocol version with changed field semantics.

Example fix

// before: swallowing the detail
match result { Err(_) => continue, Ok(p) => handle(p) }

// after: surface the custom message
match result {
    Ok(p) => handle(p),
    Err(ReadingError::Message(msg)) => warn!("decode rejected packet: {msg}"),
    Err(e) => return Err(e),
}
Defensive patterns

Strategy: try-catch

Validate before calling

// validate domain values before serializing into packets
fn valid_slot(slot: i16, hotbar_size: i16) -> bool { slot >= 0 && slot < hotbar_size }

Try / catch

match read_packet(&mut r).await {
    Err(ReadingError::Message(msg)) => {
        warn!("malformed packet content: {msg}");
        // optionally log raw bytes, then drop the connection
    }
    other => /* ... */,
}

Prevention

When it happens

Trigger: Any deserialize impl calls ReadingError::custom(...) or constructs Message directly: invalid enum variants, malformed VarInts, out-of-domain values, or a packet struct's field validation failing during decode.

Common situations: A client sending data that parses as bytes but violates the protocol's semantic rules (e.g. an unknown item id in a slot, an out-of-range position); custom packet types whose deserializer rejects impossible field combinations.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09). Data as JSON: /api/errors/d0992323276e5343. Report an issue: GitHub.

Appendix: source

Thrown at crates/pumpkin-protocol/src/ser/mod.rs:27

    },
};

use pumpkin_nbt::{
    compound::NbtCompound, deserializer::NbtReadHelper, serializer::NbtWriteHelperJava, tag::NbtTag,
};
use pumpkin_util::math::position::BlockPos;
use pumpkin_util::{text::TextComponent, version::JavaMinecraftVersion};
use thiserror::Error;

#[derive(Debug, Error)]
pub enum ReadingError {
    #[error("EOF, Tried to read {0} but No bytes left to consume")]
    CleanEOF(String),
    #[error("incomplete: {0}")]
    Incomplete(String),
    #[error("too large: {0}")]
    TooLarge(String),
    #[error("{0}")]
    Message(String),
}

impl serde::de::Error for ReadingError {
    fn custom<T: std::fmt::Display>(msg: T) -> Self {
        Self::Message(msg.to_string())
    }
}

#[derive(Debug, Error)]
pub enum WritingError {
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),
    #[error("Serde failure: {0}")]
    Serde(String),
    #[error("Packet is not supported in Minecraft version {0:?}")]
    UnsupportedVersion(JavaMinecraftVersion),
    #[error("Failed to serialize packet: {0}")]

View on GitHub (pinned to 8d4639e25a)