{"record":{"id":"a1c557b56d5a374d","repo":"Pumpkin-MC/Pumpkin","slug":"error-while-working-with-zlib-compression-0","errorCode":null,"errorMessage":"Error while working with zlib compression: {0}","messagePattern":"Error while working with zlib compression: (.+?)","errorType":"error_code","errorClass":"CompressionError","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-world/src/chunk/mod.rs","lineNumber":58,"sourceCode":"    #[error(\"Failed to parse chunk from bytes: {0}\")]\n    ParsingError(ChunkParsingError),\n}\n\n#[derive(Error, Debug)]\npub enum ChunkWritingError {\n    #[error(\"Io error: {0}\")]\n    IoError(std::io::Error),\n    #[error(\"Compression error {0}\")]\n    Compression(CompressionError),\n    #[error(\"Chunk serializing error: {0}\")]\n    ChunkSerializingError(String),\n}\n\n#[derive(Error, Debug)]\npub enum CompressionError {\n    #[error(\"Compression scheme not recognised\")]\n    UnknownCompression,\n    #[error(\"Error while working with zlib compression: {0}\")]\n    ZlibError(std::io::Error),\n    #[error(\"Error while working with Gzip compression: {0}\")]\n    GZipError(std::io::Error),\n    #[error(\"Error while working with LZ4 compression: {0}\")]\n    LZ4Error(std::io::Error),\n    #[error(\"Error while working with zstd compression: {0}\")]\n    ZstdError(std::io::Error),\n}\n\n// Clone here cause we want to clone a snapshot of the chunk so we don't block writing for too long\npub struct ChunkData {\n    pub section: ChunkSections,\n    /// See `https://minecraft.wiki/w/Heightmap` for more info\n    pub heightmap: std::sync::Mutex<ChunkHeightmaps>,\n    pub x: i32,\n    pub z: i32,\n    pub block_ticks: ChunkTickScheduler<&'static Block>,\n    pub fluid_ticks: ChunkTickScheduler<&'static Fluid>,","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-world/src/chunk/mod.rs#L40-L76","documentation":"CompressionError variant from chunk (de)compression: the underlying zlib inflate/deflate call returned an io error while processing the chunk payload. The offending input is the zlib-compressed chunk byte stream from the region file — corrupted data, truncation, or a mismatched compression id will surface here wrapped in the io error.","triggerScenarios":"Decompressing a truncated or corrupt zlib payload from a region file, or a compressor failure while encoding chunk data during save.","commonSituations":"Region files cut short by crashes or partial transfers, bit-flip disk corruption, out-of-memory during large chunk compression.","solutions":["Retry the chunk write; check disk state if persistent","Validate the zlib stream before use","Log the underlying io error"],"exampleFix":"// before\nlet raw = zlib_decode(payload).unwrap();\n// after\nlet raw = zlib_decode(payload)\n    .map_err(|e| { log::error!(\"zlib failure on chunk data: {e}\"); e })?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_zlib_failure(e: &CompressionError) -> Option<&std::io::Error> {\n    if let CompressionError::ZlibError(e) = e { Some(e) } else { None }\n}","tryCatchPattern":"match decompress_chunk(payload, Scheme::Zlib) {\n    Err(CompressionError::ZlibError(e)) => { log::error!(\"zlib: {e}\"); restore_from_backup() }\n    other => other?,\n}","preventionTips":["Checksum region files after transfers.","Detect and reject truncated region files before decompression.","Back up worlds regularly to recover from corruption."],"tags":["compression","zlib","minecraft","io"],"backgroundTag":"file-read-failed","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}