{"record":{"id":"1476556118bb2c42","repo":"Pumpkin-MC/Pumpkin","slug":"writing-packet-failed-0","errorCode":null,"errorMessage":"Writing packet failed: {0}","messagePattern":"Writing packet failed: (.+?)","errorType":"exception","errorClass":"PacketEncodeError","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/lib.rs","lineNumber":295,"sourceCode":"    fn write_packet(&self, writer: impl Write) -> Result<(), Error>;\n\n    fn serialize_packet(&self) -> Result<Bytes, Error> {\n        crate::bedrock::packet_encoder::serialize_packet(self)\n    }\n}\n\npub trait BServerPacket: Packet + Sized {\n    fn read(read: impl Read) -> Result<Self, Error>;\n}\n\n/// Errors that can occur during packet encoding.\n#[derive(Error, Debug)]\npub enum PacketEncodeError {\n    #[error(\"Packet exceeds maximum length: {0}\")]\n    TooLong(usize),\n    #[error(\"Compression failed {0}\")]\n    CompressionFailed(String),\n    #[error(\"Writing packet failed: {0}\")]\n    Message(String),\n}\n\n#[derive(Error, Debug)]\npub enum PacketDecodeError {\n    #[error(\"failed to decode packet ID\")]\n    DecodeID,\n    #[error(\"packet exceeds maximum length\")]\n    TooLong,\n    #[error(\"packet length is out of bounds\")]\n    OutOfBounds,\n    #[error(\"malformed packet length VarInt: {0}\")]\n    MalformedLength(String),\n    #[error(\"failed to decompress packet: {0}\")]\n    FailedDecompression(String), // Updated to include error details\n    #[error(\"packet is uncompressed but greater than the threshold\")]\n    NotCompressed,\n    #[error(\"the connection has closed\")]","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/lib.rs#L277-L313","documentation":"`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.","triggerScenarios":"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.","commonSituations":"Client disconnected while the server was sending a packet; TCP connection reset; writing to a network buffer that 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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match write_packet(&packet, version, &mut stream) {\n    Ok(()) => {},\n    Err(PacketEncodeError::Message(e)) if e.contains(\"Broken pipe\") || e.contains(\"reset\") => {\n        log::info!(\"client disconnected mid-packet; closing session\");\n        session.close();\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["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."],"tags":["protocol","io","network","packet-encoding"],"backgroundTag":"broken-pipe","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}