{"record":{"id":"6f550ca1af1c988b","repo":"Anuken/Mindustry","slug":"error-reading-region","errorCode":null,"errorMessage":"Error reading region \"{}\".","messagePattern":"Error reading region \"(.+?)\"\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/io/SaveFileReader.java","lineNumber":93,"sourceCode":"\n    protected static final ReusableByteOutStream byteOutput = new ReusableByteOutStream(), byteOutput2 = new ReusableByteOutStream();\n    protected static final DataOutputStream dataBytes = new DataOutputStream(byteOutput), dataBytes2 = new DataOutputStream(byteOutput2);\n    protected static final Writes writes1 = new Writes(dataBytes), writes2 = new Writes(dataBytes2);\n    protected static final Reads chunkReads = new Reads(null);\n    protected static boolean chunkNested = false;\n\n    public static String mapFallback(String name){\n        return fallback.get(name, name);\n    }\n\n    //TODO: unify readRegion with readChunk, they do the same thing and both should have good error messages\n    public void readRegion(String name, DataInput stream, CounterInputStream counter, IORunner<DataInput> cons) throws IOException{\n        counter.resetCount();\n        int length;\n        try{\n            length = readChunk(stream, (chunkStream, len) -> cons.accept(chunkStream));\n        }catch(Throwable e){\n            throw new IOException(\"Error reading region \\\"\" + name + \"\\\".\", e);\n        }\n\n        if(length != counter.count - 4){\n            throw new IOException(\"Error reading region \\\"\" + name + \"\\\": read length mismatch. Expected: \" + length + \"; Actual: \" + (counter.count - 4));\n        }\n    }\n\n    public void writeRegion(String name, DataOutput stream, IORunner<DataOutput> cons) throws IOException{\n        try{\n            writeChunk(stream, writes -> cons.accept(writes.output));\n        }catch(Throwable e){\n            throw new IOException(\"Error writing region \\\"\" + name + \"\\\".\", e);\n        }\n    }\n\n    /** Write a chunk of input to the stream. An integer of some length is written first, followed by the data. */\n    public void writeChunk(DataOutput output, IORunner<Writes> runner) throws IOException{\n        boolean wasNested = chunkNested;","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/io/SaveFileReader.java#L75-L111","documentation":"Thrown by SaveFileReader.readRegion when any Throwable escapes readChunk while reading a named save region. readRegion wraps the chunk read in try/catch and rethrows an IOException tagged with the region name, chaining the original cause. This is the generic 'something went wrong reading this region' wrapper used across save/map loading.","triggerScenarios":"Any exception (IOException, EOFException, RuntimeException) during deserialization of a save region (e.g. 'meta', 'map', 'entities') bubbles up wrapped as 'Error reading region \"<name>\".'. Caused by truncation, corruption, or a deserialization bug.","commonSituations":"Corrupt or partially-written save file; truncated download of a map; version-skew where a region's contents differ from what the reader expects; disk read error mid-stream.","solutions":["Inspect the chained cause (IOException.getCause()) for the real failure (EOF, ClassNotFound, etc.).","If the file is corrupt/truncated, restore from a backup or re-download.","If a version mismatch, load in the matching game version.","Catch IOException at the load boundary and report the region + cause to the user."],"exampleFix":"// before\nver.readRegion(\"meta\", stream, counter, cons);\n\n// after\ntry{\n    ver.readRegion(\"meta\", stream, counter, cons);\n}catch(IOException e){\n    Log.err(\"Failed reading region 'meta'\", e.getCause());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// cannot fully pre-validate a region without reading it; pre-check version instead\nif(SaveIO.getSaveWriter(version) == null){ throw new IOException(\"Unsupported save version\"); }","typeGuard":null,"tryCatchPattern":"try{ ver.readRegion(name, stream, counter, cons); }catch(IOException e){ Log.err(\"Region '\" + name + \"' unreadable\", e.getCause()); throw e; }","preventionTips":["Always inspect IOException.getCause() for the real failure.","Load saves in their authoring version.","Back up saves before migration.","Catch at the load boundary and report region + cause."],"tags":["save","io","corruption","save-compat"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}