{"record":{"id":"d0992323276e5343","repo":"Pumpkin-MC/Pumpkin","slug":"0-d09923","errorCode":null,"errorMessage":"{0}","messagePattern":"\\{0\\}","errorType":"exception","errorClass":"ReadingError","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/ser/mod.rs","lineNumber":27,"sourceCode":"    },\n};\n\nuse pumpkin_nbt::{\n    compound::NbtCompound, deserializer::NbtReadHelper, serializer::NbtWriteHelperJava, tag::NbtTag,\n};\nuse pumpkin_util::math::position::BlockPos;\nuse pumpkin_util::{text::TextComponent, version::JavaMinecraftVersion};\nuse thiserror::Error;\n\n#[derive(Debug, Error)]\npub enum ReadingError {\n    #[error(\"EOF, Tried to read {0} but No bytes left to consume\")]\n    CleanEOF(String),\n    #[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}\")]","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/ser/mod.rs#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the embedded message — it names the field or invariant that failed.","Capture the raw packet bytes for the failing stream to debug what the peer sent.","Fix the sender to produce values within the protocol's constraints.","Update the library if the peer uses a newer protocol version with changed field semantics."],"exampleFix":"// before: swallowing the detail\nmatch result { Err(_) => continue, Ok(p) => handle(p) }\n\n// after: surface the custom message\nmatch result {\n    Ok(p) => handle(p),\n    Err(ReadingError::Message(msg)) => warn!(\"decode rejected packet: {msg}\"),\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"// validate domain values before serializing into packets\nfn valid_slot(slot: i16, hotbar_size: i16) -> bool { slot >= 0 && slot < hotbar_size }","typeGuard":null,"tryCatchPattern":"match read_packet(&mut r).await {\n    Err(ReadingError::Message(msg)) => {\n        warn!(\"malformed packet content: {msg}\");\n        // optionally log raw bytes, then drop the connection\n    }\n    other => /* ... */,\n}","preventionTips":["Always log the embedded message text — it pinpoints the failing field.","Capture raw packet bytes at debug level to reproduce deserialization failures.","Keep client and server on protocol versions the library supports."],"tags":["rust","deserialization","protocol","serde"],"backgroundTag":"invalid-argument-value","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"}