Anuken/Mindustry · error · RuntimeException

Invalid code.

Error message

Invalid code. 

What it means

LParser parses in-game processor (logic) scripts into LStatements. Its error() helper prefixes any syntax problem with 'Invalid code.' and appends a detail string (e.g. missing closing quote, string too long, invalid jump). It is parsed via LAssembler (LAssembler.java:56). The input is user-authored or mod-generated text.

Source

Thrown at core/src/mindustry/logic/LParser.java:36

    private static final ObjectIntMap<String> jumpLocations = new ObjectIntMap<>();

    Seq<LStatement> statements = new Seq<>();
    char[] chars;
    int pos, line, tok;
    boolean privileged;

    LParser(String text, boolean privileged){
        this.privileged = privileged;
        this.chars = text.toCharArray();
    }

    void comment(){
        //read until \n or eof
        while(pos < chars.length && chars[pos++] != '\n');
    }

    void error(String message){
        throw new RuntimeException("Invalid code. " + message);
    }

    String string(){
        int from = pos;
        int utflen = 0;

        while(++pos < chars.length){
            char c = chars[pos];
            if(c == '\n'){
                error("Missing closing quote \" before end of line.");
            }else if(c == '"'){
                break;
            }

            // See ByteBufferOutput.writeUTF()
            utflen += c != 0 && c <= 0x7F ? 1 : c <= 0x7FF ? 2 : 3;
        }

View on GitHub (pinned to f695ad7e60)

Solutions

  1. Read the appended detail after 'Invalid code.' — it names the exact problem (e.g. 'Missing closing quote').
  2. Fix the offending line/quote in the logic editor and re-parse.
  3. If you generate code, validate that it parses before sending it to a processor.

Example fix

// before (unterminated string)
print "missing close

// after (closed quote)
print "missing close"
Defensive patterns

Strategy: validation

Validate before calling

// Parse-test a script before deploying it to a processor.
try {
    new LParser(text, privileged).parse();
} catch(RuntimeException e) {
    // The detail follows "Invalid code. "
    showParseError(e.getMessage());
}

Try / catch

try {
    LAssembler.fromLogic(text, privileged);
} catch(RuntimeException e) {
    Log.err("Logic parse error", e);
    notifyUser(e.getMessage());
}

Prevention

When it happens

Trigger: A processor/logic script with a syntax error: an unterminated string, a string over 65535 UTF bytes, a missing closing quote, or any other parse failure surfaced by error().

Common situations: Typos in the logic editor; copy-paste of malformed code; a mod generating LStatement text that does not conform; a newline placed inside a quoted string.

Related errors


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