{"record":{"id":"de166d2c9486c853","repo":"Anuken/Mindustry","slug":"invalid-code","errorCode":null,"errorMessage":"Invalid code. ","messagePattern":"Invalid code\\. ","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/logic/LParser.java","lineNumber":36,"sourceCode":"    private static final ObjectIntMap<String> jumpLocations = new ObjectIntMap<>();\n\n    Seq<LStatement> statements = new Seq<>();\n    char[] chars;\n    int pos, line, tok;\n    boolean privileged;\n\n    LParser(String text, boolean privileged){\n        this.privileged = privileged;\n        this.chars = text.toCharArray();\n    }\n\n    void comment(){\n        //read until \\n or eof\n        while(pos < chars.length && chars[pos++] != '\\n');\n    }\n\n    void error(String message){\n        throw new RuntimeException(\"Invalid code. \" + message);\n    }\n\n    String string(){\n        int from = pos;\n        int utflen = 0;\n\n        while(++pos < chars.length){\n            char c = chars[pos];\n            if(c == '\\n'){\n                error(\"Missing closing quote \\\" before end of line.\");\n            }else if(c == '\"'){\n                break;\n            }\n\n            // See ByteBufferOutput.writeUTF()\n            utflen += c != 0 && c <= 0x7F ? 1 : c <= 0x7FF ? 2 : 3;\n        }\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/logic/LParser.java#L18-L54","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["Read the appended detail after 'Invalid code.' — it names the exact problem (e.g. 'Missing closing quote').","Fix the offending line/quote in the logic editor and re-parse.","If you generate code, validate that it parses before sending it to a processor."],"exampleFix":"// before (unterminated string)\nprint \"missing close\n\n// after (closed quote)\nprint \"missing close\"","handlingStrategy":"validation","validationCode":"// Parse-test a script before deploying it to a processor.\ntry {\n    new LParser(text, privileged).parse();\n} catch(RuntimeException e) {\n    // The detail follows \"Invalid code. \"\n    showParseError(e.getMessage());\n}","typeGuard":null,"tryCatchPattern":"try {\n    LAssembler.fromLogic(text, privileged);\n} catch(RuntimeException e) {\n    Log.err(\"Logic parse error\", e);\n    notifyUser(e.getMessage());\n}","preventionTips":["Always parse-test generated logic scripts before deploying them.","Ensure quoted strings are closed on the same line and are under 65535 UTF-8 bytes.","Validate user-pasted code in the editor before running it on a processor."],"tags":["logic","parser","validation","user-input"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}