Pumpkin-MC/Pumpkin · error · WritingError
Serde failure
Error message
Serde failure: {0} What it means
WritingError::Serde(String) is the serde::ser::Error::custom implementation for the protocol's writer. It is raised when serializing a packet's fields fails semantically — the serializer refuses to encode a value (e.g. a string too long to be length-prefixed, a value violating the format's invariants) rather than failing on IO.
Solutions
- Read the embedded message to find which field failed to serialize.
- Validate packet field contents (string byte lengths, value ranges) before constructing the packet.
- Truncate or split payloads exceeding protocol limits (e.g. long chat/component JSON).
- Check custom Serialize impls for bugs introduced by your own packet types.
Example fix
// before: sending an arbitrarily long custom payload
let p = Packet::new(CustomChannel, plugin_data);
// after: enforce the protocol's length cap first
let data = if plugin_data.len() > MAX_PAYLOAD { &plugin_data[..MAX_PAYLOAD] } else { plugin_data };
let p = Packet::new(CustomChannel, data); Defensive patterns
Strategy: validation
Validate before calling
// check string sizes against the protocol's VarInt length cap before building the packet
fn fits_length_prefix(s: &str, max: usize) -> bool { s.len() <= max }
assert!(fits_length_prefix(&payload, 32767), "payload too long for packet"); Try / catch
match packet.write(&mut stream).await {
Err(WritingError::Serde(msg)) => {
error!("packet field failed to serialize: {msg}");
// fix or drop the offending packet, keep the connection alive
}
other => /* ... */,
} Prevention
- Truncate or split oversized text/component payloads before packet construction.
- Validate custom packet fields against wire-format constraints in constructors.
- Unit-test custom Serialize impls with edge-case values (max lengths, empty strings).
When it happens
Trigger: Serializing any packet via the serde writer when a field cannot be encoded: calls to WritingError::custom from Serialize impls or the length-checked encoders (strings whose byte length exceeds what a VarInt prefix allows, invalid identifiers, etc.).
Common situations: Plugins/custom code putting oversized or malformed data into a packet body; building a TextComponent that serializes to JSON too large; constructing packets manually with values the wire format cannot represent.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- Failed to serialize packet
- {0}
- JSON parse error
- Invalid slot
- Player ' ' tried to interact with a closed container
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/f8cb49ca56debe44.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-protocol/src/ser/mod.rs:41
#[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}")]
Message(String),
}
impl serde::ser::Error for WritingError {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
Self::Serde(msg.to_string())
}
}
struct NetworkReadDataSource<'a, R: NetworkReadExt + ?Sized>(&'a mut R);
impl<'a, R: NetworkReadExt + ?Sized> pumpkin_nbt::deserializer::NbtDataSource<'a>
for NetworkReadDataSource<'a, R>
{View on GitHub (pinned to 8d4639e25a)