{"record":{"id":"8af4ae903b67e0a7","repo":"Pumpkin-MC/Pumpkin","slug":"expected-i16","errorCode":null,"errorMessage":"expected i16","messagePattern":"expected i16","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/serial/deserializer.rs","lineNumber":297,"sourceCode":"        if buf.is_empty() {\n            return Err(Error::new(ErrorKind::UnexpectedEof, \"expected u8\"));\n        }\n        let b = buf[0];\n        *buf = &buf[1..];\n        Ok(b)\n    }\n}\n\nimpl<'a> PacketReadSlice<'a> for i8 {\n    fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {\n        u8::read_slice(buf).map(|b| b as Self)\n    }\n}\n\nimpl<'a> PacketReadSlice<'a> for i16 {\n    fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {\n        if buf.len() < 2 {\n            return Err(Error::new(ErrorKind::UnexpectedEof, \"expected i16\"));\n        }\n        let (bytes, rest) = buf.split_at(2);\n        *buf = rest;\n        let arr = bytes\n            .try_into()\n            .map_err(|_| Error::new(ErrorKind::InvalidData, \"invalid i16 slice\"))?;\n        Ok(Self::from_le_bytes(arr))\n    }\n}\n\nimpl<'a> PacketReadSlice<'a> for i32 {\n    fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {\n        if buf.len() < 4 {\n            return Err(Error::new(ErrorKind::UnexpectedEof, \"expected i32\"));\n        }\n        let (bytes, rest) = buf.split_at(4);\n        *buf = rest;\n        let arr = bytes","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/serial/deserializer.rs#L279-L315","documentation":"Thrown by `PacketReadSlice for i16` when fewer than 2 bytes remain in the buffer. The deserializer needs exactly 2 bytes to reconstruct a little-endian i16. It is an UnexpectedEof error from premature buffer exhaustion.","triggerScenarios":"i16::read_slice called when buf.len() < 2 — packet payload shorter than the struct layout being decoded.","commonSituations":"Truncated packet body; missing padding before an i16 field; field misalignment from a previous VarInt of wrong length.","solutions":["Ensure the packet contains at least 2 bytes for this field before decoding","Check that prior VarUInt fields parsed the correct number of bytes","Validate total payload length against the header","Handle and reject the malformed packet"],"exampleFix":"// before\nlet temp = i16::read_slice(&mut buf)?;\n// after\nif buf.len() < 2 { return Err(PacketError::Truncated); }\nlet temp = i16::read_slice(&mut buf)?;","handlingStrategy":"try-catch","validationCode":"if buf.len() < 2 { return Err(PacketError::Truncated); }","typeGuard":null,"tryCatchPattern":"let v = i16::read_slice(&mut buf)\n    .map_err(|e| { log::debug!(\"short read: {e}\"); PacketError::Truncated })?;","preventionTips":["Verify VarUInt field byte counts to avoid downstream misalignment","Validate payload length against the packet header first","Handle UnexpectedEof distinctly from other decode errors"],"tags":["protocol","serialization","truncated-packet"],"backgroundTag":"unexpected-eof","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}