From 1b3517e83b8079e6b26b62bdd9ca42ecf9937e63 Mon Sep 17 00:00:00 2001 From: arcade_kappa Date: Sat, 7 Dec 2024 11:44:31 +0800 Subject: [PATCH] Better mixin error handling --- .../fml/common/FMLContextQuery.java | 2 +- .../fml/common/LoadController.java | 20 ++++++++++++------- .../fml/relauncher/MixinBooterPlugin.java | 9 ++++----- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/common/FMLContextQuery.java b/src/main/java/net/minecraftforge/fml/common/FMLContextQuery.java index 23c4f428e..30754cd8b 100644 --- a/src/main/java/net/minecraftforge/fml/common/FMLContextQuery.java +++ b/src/main/java/net/minecraftforge/fml/common/FMLContextQuery.java @@ -29,7 +29,7 @@ private FMLContextQuery() { modApiManager$dataTable.setAccessible(true); asmDataTable = (ASMDataTable) modApiManager$dataTable.get(ModAPIManager.INSTANCE); } catch (ReflectiveOperationException e) { - MixinBooterPlugin.LOGGER.fatal("Not able to reflect ModAPIManager#dataTable", e); + FMLLog.log.fatal("Not able to reflect ModAPIManager#dataTable", e); } this.asmDataTable = asmDataTable; } diff --git a/src/main/java/net/minecraftforge/fml/common/LoadController.java b/src/main/java/net/minecraftforge/fml/common/LoadController.java index cd6da0883..62255c7e2 100644 --- a/src/main/java/net/minecraftforge/fml/common/LoadController.java +++ b/src/main/java/net/minecraftforge/fml/common/LoadController.java @@ -165,17 +165,21 @@ public void distributeStateMessage(LoaderState state, Object... eventData) FMLContextQuery.init(); // Initialize FMLContextQuery and add it to the global list - MixinBooterPlugin.LOGGER.info("Instantiating all ILateMixinLoader implemented classes..."); + FMLLog.log.info("Instantiating all ILateMixinLoader implemented classes..."); for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class.getName().replace('.', '/'))) { modClassLoader.addFile(asmData.getCandidate().getModContainer()); // Add to path before `newInstance` Class clazz = Class.forName(asmData.getClassName().replace('/', '.')); - MixinBooterPlugin.LOGGER.info("Instantiating {} for its mixins.", clazz); - ILateMixinLoader loader = (ILateMixinLoader) clazz.newInstance(); + FMLLog.log.info("Instantiating {} for its mixins.", clazz); + ILateMixinLoader loader = (ILateMixinLoader) clazz.getConstructor().newInstance(); for (String mixinConfig : loader.getMixinConfigs()) { if (loader.shouldMixinConfigQueue(mixinConfig)) { - MixinBooterPlugin.LOGGER.info("Adding {} mixin configuration.", mixinConfig); - Mixins.addConfiguration(mixinConfig); - loader.onMixinConfigQueued(mixinConfig); + FMLLog.log.info("Adding {} mixin configuration.", mixinConfig); + try { + Mixins.addConfiguration(mixinConfig); + loader.onMixinConfigQueued(mixinConfig); + } catch (Throwable t) { + FMLLog.log.error("Error adding mixin configuration for {}", mixinConfig, t); + } } } } @@ -183,7 +187,9 @@ public void distributeStateMessage(LoaderState state, Object... eventData) for (ModContainer container : this.loader.getActiveModList()) { modClassLoader.addFile(container.getSource()); } - } catch (Throwable ignored) {} + } catch (Throwable t) { + FMLLog.log.error("Error loading Mods", t); + } if (MixinService.getService() instanceof MixinServiceLaunchWrapper) { ((MixinServiceLaunchWrapper) MixinService.getService()).setDelegatedTransformers(null); } diff --git a/src/main/java/net/minecraftforge/fml/relauncher/MixinBooterPlugin.java b/src/main/java/net/minecraftforge/fml/relauncher/MixinBooterPlugin.java index 61eeec535..06040159e 100644 --- a/src/main/java/net/minecraftforge/fml/relauncher/MixinBooterPlugin.java +++ b/src/main/java/net/minecraftforge/fml/relauncher/MixinBooterPlugin.java @@ -2,6 +2,7 @@ import net.minecraft.launchwrapper.Launch; import net.minecraftforge.common.ForgeVersion; +import net.minecraftforge.fml.common.FMLLog; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixins; @@ -17,8 +18,6 @@ @IFMLLoadingPlugin.SortingIndex(1) public final class MixinBooterPlugin implements IFMLLoadingPlugin { - public static final Logger LOGGER = LogManager.getLogger("MixinBooter"); - public MixinBooterPlugin() { } @@ -50,17 +49,17 @@ public void injectData(Map data) { } Object theMod = fmlPluginWrapper$coreModInstance.get(coremod); if (theMod instanceof IEarlyMixinLoader loader) { - LOGGER.info("Grabbing {} for its mixins.", loader.getClass()); + FMLLog.log.info("Grabbing {} for its mixins.", loader.getClass()); for (String mixinConfig : loader.getMixinConfigs()) { if (loader.shouldMixinConfigQueue(mixinConfig)) { - LOGGER.info("Adding {} mixin configuration.", mixinConfig); + FMLLog.log.info("Adding {} mixin configuration.", mixinConfig); Mixins.addConfiguration(mixinConfig); loader.onMixinConfigQueued(mixinConfig);; } } } } catch (Throwable t) { - LOGGER.error("Unexpected error", t); + FMLLog.log.error("Unexpected error handling early mixins", t); } } }