{"record":{"id":"cd2d6205cf157218","repo":"Anuken/Mindustry","slug":"mod-is-not-loaded-yet-or-missing","errorCode":null,"errorMessage":"Mod is not loaded yet (or missing)!","messagePattern":"Mod is not loaded yet \\(or missing\\)!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/mod/Mods.java","lineNumber":71,"sourceCode":"\n    Seq<LoadedMod> mods = new Seq<>();\n    private Seq<LoadedMod> newImports = new Seq<>();\n    private ObjectMap<Class<?>, ModMeta> metas = new ObjectMap<>();\n    private boolean requiresReload;\n\n    public Mods(){\n        Events.on(ClientLoadEvent.class, e -> Core.app.post(this::checkWarnings));\n    }\n\n    /** @return the main class loader for all mods */\n    public ClassLoader mainLoader(){\n        return mainLoader;\n    }\n\n    /** @return the folder where configuration files for this mod should go. Call this in init(). */\n    public Fi getConfigFolder(Mod mod){\n        ModMeta load = metas.get(mod.getClass());\n        if(load == null) throw new IllegalArgumentException(\"Mod is not loaded yet (or missing)!\");\n        Fi result = modDirectory.child(load.name);\n        result.mkdirs();\n        return result;\n    }\n\n    /** @return a file named 'config.json' in the config folder for the specified mod.\n     * Call this in init(). */\n    public Fi getConfig(Mod mod){\n        return getConfigFolder(mod).child(\"config.json\");\n    }\n\n    /** Returns a list of files per mod subdirectory. */\n    public void listFiles(String directory, Cons2<LoadedMod, Fi> cons){\n        eachEnabled(mod -> {\n            Fi file = mod.root.child(directory);\n            if(file.exists()){\n                for(Fi child : file.list()){\n                    if(!child.isDirectory()){","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/mod/Mods.java#L53-L89","documentation":"Mods.getConfigFolder maps a Mod instance to its ModMeta via the metas registry. If no meta is registered for that mod class, it means the mod has not finished loading/registration yet, and an IllegalArgumentException is thrown. getConfig() delegates here.","triggerScenarios":"A mod calls getConfigFolder/getConfig from its constructor or any callback that runs before the mod is registered in the metas map.","commonSituations":"Mod reads config in its constructor instead of init(); plugin instantiated outside the normal load flow; calling getConfig on a mod object that is not the loaded instance.","solutions":["Move all getConfig()/getConfigFolder() calls into the mod's init() method (documented requirement).","Ensure you call getConfig on the actual loaded Mod instance, not a fresh one.","Do not access config during class construction or static init."],"exampleFix":"// before\npublic class MyMod extends Mod {\n    public MyMod() {\n        Fi cfg = getConfig(); // throws: not loaded yet\n    }\n}\n\n// after\npublic class MyMod extends Mod {\n    @Override\n    public void init() {\n        Fi cfg = getConfig();\n    }\n}","handlingStrategy":"validation","validationCode":"// Only fetch config once the mod is registered.\nif(!mods.getMods().anyMatch(m -> m.main == this)) {\n    throw new IllegalStateException(\"getConfig called before mod registration; move to init().\");\n}\nFi cfg = getConfig();","typeGuard":null,"tryCatchPattern":"try {\n    Fi cfg = getConfig();\n} catch(IllegalArgumentException e) {\n    if(e.getMessage().equals(\"Mod is not loaded yet (or missing)!\")) { /* defer to init() */ }\n    else throw e;\n}","preventionTips":["Never call getConfig()/getConfigFolder() in the mod constructor or static init.","Perform all config I/O in init().","Call getConfig on the loaded instance, not a newly constructed one."],"tags":["modding","lifecycle","config","api-misuse"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}