{"record":{"id":"f8cb49ca56debe44","repo":"Pumpkin-MC/Pumpkin","slug":"serde-failure-0","errorCode":null,"errorMessage":"Serde failure: {0}","messagePattern":"Serde failure: (.+?)","errorType":"exception","errorClass":"WritingError","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/ser/mod.rs","lineNumber":41,"sourceCode":"    #[error(\"incomplete: {0}\")]\n    Incomplete(String),\n    #[error(\"too large: {0}\")]\n    TooLarge(String),\n    #[error(\"{0}\")]\n    Message(String),\n}\n\nimpl serde::de::Error for ReadingError {\n    fn custom<T: std::fmt::Display>(msg: T) -> Self {\n        Self::Message(msg.to_string())\n    }\n}\n\n#[derive(Debug, Error)]\npub enum WritingError {\n    #[error(\"IO error: {0}\")]\n    IoError(#[from] std::io::Error),\n    #[error(\"Serde failure: {0}\")]\n    Serde(String),\n    #[error(\"Packet is not supported in Minecraft version {0:?}\")]\n    UnsupportedVersion(JavaMinecraftVersion),\n    #[error(\"Failed to serialize packet: {0}\")]\n    Message(String),\n}\n\nimpl serde::ser::Error for WritingError {\n    fn custom<T: std::fmt::Display>(msg: T) -> Self {\n        Self::Serde(msg.to_string())\n    }\n}\n\nstruct NetworkReadDataSource<'a, R: NetworkReadExt + ?Sized>(&'a mut R);\n\nimpl<'a, R: NetworkReadExt + ?Sized> pumpkin_nbt::deserializer::NbtDataSource<'a>\n    for NetworkReadDataSource<'a, R>\n{","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/ser/mod.rs#L23-L59","documentation":"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.","triggerScenarios":"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.).","commonSituations":"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.","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."],"exampleFix":"// before: sending an arbitrarily long custom payload\nlet p = Packet::new(CustomChannel, plugin_data);\n\n// after: enforce the protocol's length cap first\nlet data = if plugin_data.len() > MAX_PAYLOAD { &plugin_data[..MAX_PAYLOAD] } else { plugin_data };\nlet p = Packet::new(CustomChannel, data);","handlingStrategy":"validation","validationCode":"// check string sizes against the protocol's VarInt length cap before building the packet\nfn fits_length_prefix(s: &str, max: usize) -> bool { s.len() <= max }\nassert!(fits_length_prefix(&payload, 32767), \"payload too long for packet\");","typeGuard":null,"tryCatchPattern":"match packet.write(&mut stream).await {\n    Err(WritingError::Serde(msg)) => {\n        error!(\"packet field failed to serialize: {msg}\");\n        // fix or drop the offending packet, keep the connection alive\n    }\n    other => /* ... */,\n}","preventionTips":["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)."],"tags":["rust","serialization","serde","protocol"],"backgroundTag":"json-serialization-failed","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"}