Anuken/Mindustry · error · IllegalArgumentException

You are missing a " ". It must be added before the file can…

Error message

You are missing a "${key}". It must be added before the file can be parsed.

What it means

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.

Solutions

  1. Add the named key with a valid string value to the JSON.
  2. Confirm the field name spelling matches the message exactly.

Example fix

// before
{ "name": "my-thing" }  // type missing
// after
{ "name": "my-thing", "type": "flying" }
Defensive patterns

Strategy: validation

Validate before calling

if(!value.has(key)){
    throw new IllegalStateException("Missing required field '" + key + "' in " + value.toString());
}

Prevention

When it happens

Trigger: 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.

Common situations: A unit/block/etc. JSON missing the required "type" field; refactoring that introduces a new required field.

Related errors


AI-assisted analysis of Anuken/Mindustry@f695ad7e60 (2026-08-14). Data as JSON: /api/errors/de0927def77243f8. Report an issue: GitHub.

Appendix: source

Thrown at core/src/mindustry/mod/ContentParser.java:907

            case "flying" -> UnitEntity::create;
            case "mech" -> MechUnit::create;
            case "legs" -> LegsUnit::create;
            case "naval" -> UnitWaterMove::create;
            case "payload" -> PayloadUnit::create;
            case "missile" -> TimedKillUnit::create;
            case "tank" -> TankUnit::create;
            case "hover" -> ElevationMoveUnit::create;
            case "tether" -> BuildingTetherPayloadUnit::create;
            case "crawl" -> CrawlUnit::create;
            default -> throw new IllegalArgumentException("Invalid unit type: '" + value.asString() + "'. Must be 'flying/mech/legs/naval/payload/missile/tether/crawl'.");
        };
    }

    private String getString(JsonValue value, String key){
        if(value.has(key)){
            return value.getString(key);
        }else{
            throw new IllegalArgumentException("You are missing a \"" + key + "\". It must be added before the file can be parsed.");
        }
    }

    private String getType(JsonValue value){
        return getString(value, "type");
    }

    private <T extends Content> T find(ContentType type, String name){
        Content c = Vars.content.getByName(type, name);
        if(c == null && currentMod != null) c = Vars.content.getByName(type, currentMod.name + "-" + name);
        if(c == null) throw new IllegalArgumentException("No " + type + " found with name '" + name + "'");
        return (T)c;
    }

    private <T extends Content> TypeParser<T> parser(ContentType type, Func<String, T> constructor){
        return (mod, name, value) -> {
            T item;
            if(allowPatching && locate(type, name) != null){

View on GitHub (pinned to f695ad7e60)