{"record":{"id":"5561c3a82bf3134e","repo":"Anuken/Mindustry","slug":"error-loading-mod-mod-meta-name","errorCode":null,"errorMessage":"Error loading mod {mod.meta.name}","messagePattern":"Error loading mod (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/mod/Mods.java","lineNumber":1000,"sourceCode":"    public Seq<LoadedMod> getMods(){\n        return mods;\n    }\n\n    /** Iterates through each mod with a main class. */\n    public void eachClass(Cons<Mod> cons){\n        orderedMods().each(p -> p.main != null, p -> contextRun(p, () -> cons.get(p.main)));\n    }\n\n    /** Iterates through each enabled mod. */\n    public void eachEnabled(Cons<LoadedMod> cons){\n        orderedMods().each(LoadedMod::enabled, cons);\n    }\n\n    public void contextRun(LoadedMod mod, Runnable run){\n        try{\n            run.run();\n        }catch(Throwable t){\n            throw new RuntimeException(\"Error loading mod \" + mod.meta.name, t);\n        }\n    }\n\n    /** Tries to find the config file of a mod/plugin. */\n    public @Nullable ModMeta findMeta(Fi file){\n        Fi metaFile = null;\n        for(String name : metaFiles){\n            if((metaFile = file.child(name)).exists()){\n                break;\n            }\n        }\n\n        if(!metaFile.exists()){\n            return null;\n        }\n\n        ModMeta meta = json.fromJson(ModMeta.class, Jval.read(metaFile.readString()).toString(Jformat.plain));\n        meta.cleanup();","sourceCodeStart":982,"sourceCodeEnd":1018,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/mod/Mods.java#L982-L1018","documentation":"Mods.contextRun executes a runnable within a mod's context and wraps any thrown Throwable in a RuntimeException prefixed with the mod's name, so failures during mod callbacks are attributed. The original exception is the cause.","triggerScenarios":"Any exception thrown while invoking a mod's lifecycle callback (init, load, etc.) routed through contextRun.","commonSituations":"Mod throws NPE/IllegalState during init; mod code incompatible with current game API; missing dependency at runtime.","solutions":["Inspect the wrapped cause (getCause()) — the real failure and its stack trace identify the mod line.","Fix the mod code at the indicated location.","If the cause is an API/version issue, align the mod with the running game version."],"exampleFix":"// before\ncontextRun(mod, () -> mod.init()); // wraps: 'Error loading mod X' caused by NPE in MyMod.init:42\n// fix MyMod.init line 42 to avoid the null dereference","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    mods.contextRun(mod, () -> mod.init());\n} catch(RuntimeException wrapper) {\n    Throwable cause = wrapper.getCause(); // the real exception, attributed to mod.meta.name\n    log.error(\"Mod {} failed: {}\", mod.meta.name, cause, cause);\n}","preventionTips":["Always inspect the wrapped cause, not just the outer message.","Test mods against the exact target game version.","Guard mod init code against null/missing game state."],"tags":["modding","lifecycle","error-handling","diagnostics"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}