{"record":{"id":"de0927def77243f8","repo":"Anuken/Mindustry","slug":"you-are-missing-a-key-it-must-be-added-befor","errorCode":null,"errorMessage":"You are missing a \"${key}\". It must be added before the file can be parsed.","messagePattern":"You are missing a \"(.+?)\"\\. It must be added before the file can be parsed\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/mod/ContentParser.java","lineNumber":907,"sourceCode":"            case \"flying\" -> UnitEntity::create;\n            case \"mech\" -> MechUnit::create;\n            case \"legs\" -> LegsUnit::create;\n            case \"naval\" -> UnitWaterMove::create;\n            case \"payload\" -> PayloadUnit::create;\n            case \"missile\" -> TimedKillUnit::create;\n            case \"tank\" -> TankUnit::create;\n            case \"hover\" -> ElevationMoveUnit::create;\n            case \"tether\" -> BuildingTetherPayloadUnit::create;\n            case \"crawl\" -> CrawlUnit::create;\n            default -> throw new IllegalArgumentException(\"Invalid unit type: '\" + value.asString() + \"'. Must be 'flying/mech/legs/naval/payload/missile/tether/crawl'.\");\n        };\n    }\n\n    private String getString(JsonValue value, String key){\n        if(value.has(key)){\n            return value.getString(key);\n        }else{\n            throw new IllegalArgumentException(\"You are missing a \\\"\" + key + \"\\\". It must be added before the file can be parsed.\");\n        }\n    }\n\n    private String getType(JsonValue value){\n        return getString(value, \"type\");\n    }\n\n    private <T extends Content> T find(ContentType type, String name){\n        Content c = Vars.content.getByName(type, name);\n        if(c == null && currentMod != null) c = Vars.content.getByName(type, currentMod.name + \"-\" + name);\n        if(c == null) throw new IllegalArgumentException(\"No \" + type + \" found with name '\" + name + \"'\");\n        return (T)c;\n    }\n\n    private <T extends Content> TypeParser<T> parser(ContentType type, Func<String, T> constructor){\n        return (mod, name, value) -> {\n            T item;\n            if(allowPatching && locate(type, name) != null){","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/mod/ContentParser.java#L889-L925","documentation":"getString(value, key) throws when value.has(key) is false. It is a helper used to read mandatory string fields (e.g. getType() requires \"type\"). The message names the exact missing key so the author knows what to add.","triggerScenarios":"A content JSON omits a field that getString was asked to read (currently \"type\" via getType()). Any caller of getString passing a key the JSON lacks triggers it.","commonSituations":"A unit/block/etc. JSON missing the required \"type\" field; refactoring that introduces a new required field.","solutions":["Add the named key with a valid string value to the JSON.","Confirm the field name spelling matches the message exactly."],"exampleFix":"// before\n{ \"name\": \"my-thing\" }  // type missing\n// after\n{ \"name\": \"my-thing\", \"type\": \"flying\" }","handlingStrategy":"validation","validationCode":"if(!value.has(key)){\n    throw new IllegalStateException(\"Missing required field '\" + key + \"' in \" + value.toString());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add all required fields (notably \"type\") to content JSON.","Use the exact key names from the helper."],"tags":["mindustry","modding","json","content-parser","missing-field"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}