Pumpkin-MC/Pumpkin · error · PacketEncodeError
Writing packet failed
Error message
Writing packet failed: {0} What it means
`PacketEncodeError::Message` wraps a generic I/O failure that occurred while writing the serialized packet bytes to the underlying writer. The inner io::Error description is embedded in the message. It means packet construction itself was fine but the write step failed.
Solutions
- Check connection state before writing; treat this as a dead connection and clean it up.
- Inspect the inner io::Error message for the root cause (broken pipe vs reset vs aborted).
- Add disconnect handling so write failures are logged and the player/session is removed gracefully.
- Avoid sending packets to sessions already flagged as closed.
Defensive patterns
Strategy: try-catch
Try / catch
match write_packet(&packet, version, &mut stream) {
Ok(()) => {},
Err(PacketEncodeError::Message(e)) if e.contains("Broken pipe") || e.contains("reset") => {
log::info!("client disconnected mid-packet; closing session");
session.close();
}
Err(e) => return Err(e.into()),
} Prevention
- Check connection liveness before sending.
- Route all sends through a per-session writer that handles disconnects once.
- Log inner io error kinds to distinguish disconnects from real failures.
When it happens
Trigger: Any io::Error bubbling out of `write_packet`'s writer — a closed socket (broken pipe), a full/failed buffer, or the underlying connection being reset mid-write.
Common situations: Client disconnected while the server was sending a packet; TCP connection reset; writing to a network buffer that failed.
Related errors
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/1476556118bb2c42.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-protocol/src/lib.rs:295
fn write_packet(&self, writer: impl Write) -> Result<(), Error>;
fn serialize_packet(&self) -> Result<Bytes, Error> {
crate::bedrock::packet_encoder::serialize_packet(self)
}
}
pub trait BServerPacket: Packet + Sized {
fn read(read: impl Read) -> Result<Self, Error>;
}
/// Errors that can occur during packet encoding.
#[derive(Error, Debug)]
pub enum PacketEncodeError {
#[error("Packet exceeds maximum length: {0}")]
TooLong(usize),
#[error("Compression failed {0}")]
CompressionFailed(String),
#[error("Writing packet failed: {0}")]
Message(String),
}
#[derive(Error, Debug)]
pub enum PacketDecodeError {
#[error("failed to decode packet ID")]
DecodeID,
#[error("packet exceeds maximum length")]
TooLong,
#[error("packet length is out of bounds")]
OutOfBounds,
#[error("malformed packet length VarInt: {0}")]
MalformedLength(String),
#[error("failed to decompress packet: {0}")]
FailedDecompression(String), // Updated to include error details
#[error("packet is uncompressed but greater than the threshold")]
NotCompressed,
#[error("the connection has closed")]View on GitHub (pinned to 8d4639e25a)