{"record":{"id":"5a3f840b9c597ff5","repo":"Pumpkin-MC/Pumpkin","slug":"region-is-invalid","errorCode":null,"errorMessage":"Region is invalid","messagePattern":"Region is invalid","errorType":"error_code","errorClass":"ChunkReadingError","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-world/src/chunk/mod.rs","lineNumber":34,"sourceCode":"use thiserror::Error;\n\npub mod format;\npub mod io;\npub mod palette;\n\n// TODO\npub const CHUNK_WIDTH: usize = BlockPalette::SIZE;\npub const CHUNK_AREA: usize = CHUNK_WIDTH * CHUNK_WIDTH;\npub const BIOME_VOLUME: usize = BiomePalette::VOLUME;\npub const SUBCHUNK_VOLUME: usize = CHUNK_AREA * CHUNK_WIDTH;\n\n#[derive(Error, Debug)]\npub enum ChunkReadingError {\n    #[error(\"Io error: {0}\")]\n    IoError(std::io::Error),\n    #[error(\"Invalid header\")]\n    InvalidHeader,\n    #[error(\"Region is invalid\")]\n    RegionIsInvalid,\n    #[error(\"Compression error {0}\")]\n    Compression(CompressionError),\n    #[error(\"Tried to read chunk which does not exist\")]\n    ChunkNotExist,\n    #[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}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-world/src/chunk/mod.rs#L16-L52","documentation":"ChunkReadingError::RegionIsInvalid is returned when an Anvil region file being read does not have a valid region file structure. The library throws it because the region header or region location data is malformed, so chunks in that region cannot be safely located or read.","triggerScenarios":"Reading a chunk from a region file whose header (magic number / offsets table) is corrupt, truncated, or not actually a MCA region file.","commonSituations":"World files corrupted by crashes or disk issues, copying/partially downloading region files, pointing the world loader at a non-region file (e.g. a wrongly named or empty placeholder file).","solutions":["Verify the .mca region file is complete and uncorrupted (correct size, valid 8KiB header).","Restore the region file from a backup or regenerate the region with a Minecraft tool like MCASelector.","Check that the world directory layout and region file naming follow the Anvil format.","Catch this variant and treat the region as unreadable instead of crashing the server."],"exampleFix":"// before: unwrap and crash on corrupt region\nlet chunk = reader.read_chunk(pos).unwrap();\n// after\nlet chunk = match reader.read_chunk(pos) {\n    Ok(c) => c,\n    Err(ChunkReadingError::RegionIsInvalid) => { log::error!(\"corrupt region file; skipping\"); return; }\n    Err(e) => return Err(e),\n};","handlingStrategy":"try-catch","validationCode":"let header = std::fs::read(&region_path)?;\nif header.len() < 8192 { return Err(\"region file too small / truncated\"); }","typeGuard":"fn is_valid_region(file: &[u8]) -> bool { file.len() >= 8192 }","tryCatchPattern":"match reader.read_chunk(pos) {\n    Err(ChunkReadingError::RegionIsInvalid) => skip_region(),\n    other => other?,\n}","preventionTips":["Back up region files before running third-party tools.","Validate region file sizes and headers on world load.","Shut the server down cleanly to avoid truncated writes."],"tags":["minecraft","region-file","io","corruption"],"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-16T04:17:20.429Z"}