{"record":{"id":"d1e4bc3721948b09","repo":"Anuken/Mindustry","slug":"invalid-unit-type-value-asstring-must-be","errorCode":null,"errorMessage":"Invalid unit type: '${value.asString()}'. Must be 'flying/mech/legs/naval/payload/missile/tether/crawl'.","messagePattern":"Invalid unit type: '(.+?)'\\. Must be 'flying/mech/legs/naval/payload/missile/tether/crawl'\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/mod/ContentParser.java","lineNumber":899,"sourceCode":"            read(() -> readFields(entry, value));\n            return entry;\n        }\n    );\n\n    Prov<Unit> unitType(JsonValue value){\n        if(value == null) return UnitEntity::create;\n        return switch(value.asString()){\n            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);","sourceCodeStart":881,"sourceCodeEnd":917,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/mod/ContentParser.java#L881-L917","documentation":"unitType() switches on the \"type\" string to pick the entity constructor. The default branch throws. NOTE: the error message lists only 'flying/mech/legs/naval/payload/missile/tether/crawl', but the switch ALSO accepts 'tank' and 'hover' — the message is stale/misleading and omits two valid options.","triggerScenarios":"A unit JSON \"type\" value matches none of the switch cases. Note 'tank' and 'hover' actually work despite being absent from the message.","commonSituations":"Typo in the type string; using an unsupported type name; trusting the error message's list and believing 'tank'/'hover' are invalid when they are valid.","solutions":["Use one of the actually-supported types: flying, mech, legs, naval, payload, missile, tank, hover, tether, crawl.","Check for typos against the switch in ContentParser.java:888-899 (the source of truth, not the message).","Report/ignore the message's omission of tank and hover."],"exampleFix":"// before\n\"type\": \"walker\"\n// after\n\"type\": \"legs\"","handlingStrategy":"validation","validationCode":"// Validate against the TRUE supported set (includes tank/hover, unlike the message).\nSet<String> valid = Set.of(\"flying\",\"mech\",\"legs\",\"naval\",\"payload\",\"missile\",\"tank\",\"hover\",\"tether\",\"crawl\");\nJsonValue t = value.get(\"type\");\nif(t != null && t.isString() && !valid.contains(t.asString())){\n    throw new IllegalStateException(\"Unsupported unit type '\" + t.asString() + \"'\");\n}","typeGuard":"boolean isUnitType(String s){\n    return Set.of(\"flying\",\"mech\",\"legs\",\"naval\",\"payload\",\"missile\",\"tank\",\"hover\",\"tether\",\"crawl\").contains(s);\n}","tryCatchPattern":null,"preventionTips":["Trust the switch cases in ContentParser.java, not the error message (tank/hover are valid).","Centralize the valid-type set in a constant."],"tags":["mindustry","modding","json","content-parser","unit","type","misleading-message"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}