Commit eba02e139795357549db82a214550e6f6a637ee0

Authored by Mumfrey
1 parent 5f482b2d

Catch and report mixin registration errors as critical errors in the GUI

src/client/java/com/mumfrey/liteloader/client/gui/GuiPanelLiteLoaderLog.java
@@ -290,6 +290,9 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent @@ -290,6 +290,9 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent
290 if (logLine.startsWith("tweakClass '")) return 0x5555FF; 290 if (logLine.startsWith("tweakClass '")) return 0x5555FF;
291 if (logLine.startsWith("baking listener list")) return 0x00AAAA; 291 if (logLine.startsWith("baking listener list")) return 0x00AAAA;
292 if (logLine.startsWith("generating new event handler")) return 0xFFFF55; 292 if (logLine.startsWith("generating new event handler")) return 0xFFFF55;
  293 + if (logLine.startsWith("resolving mods")) return 0xFFAA00;
  294 + if (logLine.startsWith("resolved artefact")) return 0x00AA00;
  295 + if (logLine.startsWith("evicting")) return 0xFFAA00;
293 296
294 return 0xCCCCCC; 297 return 0xCCCCCC;
295 } 298 }
src/main/java/com/mumfrey/liteloader/core/LiteLoaderEnumerator.java
@@ -122,7 +122,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator @@ -122,7 +122,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
122 private final FastIterableDeque<EnumerationObserver> observers = new HandlerList<EnumerationObserver>(EnumerationObserver.class); 122 private final FastIterableDeque<EnumerationObserver> observers = new HandlerList<EnumerationObserver>(EnumerationObserver.class);
123 123
124 protected EnumeratorState state = EnumeratorState.INIT; 124 protected EnumeratorState state = EnumeratorState.INIT;
125 - 125 +
126 /** 126 /**
127 * @param environment 127 * @param environment
128 * @param properties 128 * @param properties
@@ -144,7 +144,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator @@ -144,7 +144,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
144 // Initialise the shared mod list if we haven't already 144 // Initialise the shared mod list if we haven't already
145 this.getSharedModList(); 145 this.getSharedModList();
146 } 146 }
147 - 147 +
148 /** 148 /**
149 * @param environment 149 * @param environment
150 */ 150 */
@@ -665,7 +665,15 @@ public class LiteLoaderEnumerator implements LoaderEnumerator @@ -665,7 +665,15 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
665 if (config.endsWith(".json")) 665 if (config.endsWith(".json"))
666 { 666 {
667 LiteLoaderLogger.info(Verbosity.REDUCED, "Registering mixin config %s for %s", config, container.getName()); 667 LiteLoaderLogger.info(Verbosity.REDUCED, "Registering mixin config %s for %s", config, container.getName());
668 - Mixins.addConfiguration(config); 668 + try
  669 + {
  670 + Mixins.addConfiguration(config);
  671 + }
  672 + catch (Throwable th)
  673 + {
  674 + LiteLoaderLogger.severe(th, "Error registering mixin config %s for %s", config, container);
  675 + container.registerMixinError(th);
  676 + }
669 } 677 }
670 else if (config.contains(".json@")) 678 else if (config.contains(".json@"))
671 { 679 {
src/main/java/com/mumfrey/liteloader/core/LiteLoaderMods.java
@@ -24,6 +24,7 @@ import com.mumfrey.liteloader.interfaces.FastIterableDeque; @@ -24,6 +24,7 @@ import com.mumfrey.liteloader.interfaces.FastIterableDeque;
24 import com.mumfrey.liteloader.interfaces.Loadable; 24 import com.mumfrey.liteloader.interfaces.Loadable;
25 import com.mumfrey.liteloader.interfaces.LoadableMod; 25 import com.mumfrey.liteloader.interfaces.LoadableMod;
26 import com.mumfrey.liteloader.interfaces.LoaderEnumerator; 26 import com.mumfrey.liteloader.interfaces.LoaderEnumerator;
  27 +import com.mumfrey.liteloader.interfaces.MixinContainer;
27 import com.mumfrey.liteloader.interfaces.TweakContainer; 28 import com.mumfrey.liteloader.interfaces.TweakContainer;
28 import com.mumfrey.liteloader.launch.ClassTransformerManager; 29 import com.mumfrey.liteloader.launch.ClassTransformerManager;
29 import com.mumfrey.liteloader.launch.LoaderEnvironment; 30 import com.mumfrey.liteloader.launch.LoaderEnvironment;
@@ -444,6 +445,12 @@ public class LiteLoaderMods @@ -444,6 +445,12 @@ public class LiteLoaderMods
444 String identifier = mod.getIdentifier(); 445 String identifier = mod.getIdentifier();
445 if (identifier == null || this.environment.getEnabledModsList().isEnabled(this.environment.getProfile(), identifier)) 446 if (identifier == null || this.environment.getEnabledModsList().isEnabled(this.environment.getProfile(), identifier))
446 { 447 {
  448 + if (!this.validateMixins(mod, container))
  449 + {
  450 + this.onModLoadFailed(container, identifier, "mixins for the specified mod encountered a startup error", null);
  451 + continue;
  452 + }
  453 +
447 if (!this.enumerator.checkDependencies(container)) 454 if (!this.enumerator.checkDependencies(container))
448 { 455 {
449 this.onModLoadFailed(container, identifier, "the mod was missing a required dependency", null); 456 this.onModLoadFailed(container, identifier, "the mod was missing a required dependency", null);
@@ -474,6 +481,23 @@ public class LiteLoaderMods @@ -474,6 +481,23 @@ public class LiteLoaderMods
474 this.observers.all().onPostModLoaded(mod); 481 this.observers.all().onPostModLoaded(mod);
475 } 482 }
476 } 483 }
  484 +
  485 + private boolean validateMixins(ModInfo<?> mod, LoadableMod<?> container)
  486 + {
  487 + if (container instanceof MixinContainer)
  488 + {
  489 + @SuppressWarnings("unchecked")
  490 + Collection<Throwable> errors = ((MixinContainer<File>)container).getMixinErrors();
  491 + for (Throwable error : errors)
  492 + {
  493 + this.registerModStartupError(mod, error, true);
  494 + }
  495 +
  496 + return errors.size() == 0;
  497 + }
  498 +
  499 + return true;
  500 + }
477 501
478 /** 502 /**
479 * @param identifier 503 * @param identifier
@@ -697,26 +721,28 @@ public class LiteLoaderMods @@ -697,26 +721,28 @@ public class LiteLoaderMods
697 721
698 for (Mod mod : this.loadedMods) 722 for (Mod mod : this.loadedMods)
699 { 723 {
700 - if (mod.hasClassTransformers()) 724 + if (!mod.hasClassTransformers())
701 { 725 {
702 - List<String> modTransformers = ((TweakContainer<?>)mod.getContainer()).getClassTransformerClassNames();  
703 - for (String modTransformer : modTransformers) 726 + continue;
  727 + }
  728 +
  729 + List<String> modTransformers = ((TweakContainer<?>)mod.getContainer()).getClassTransformerClassNames();
  730 + for (String modTransformer : modTransformers)
  731 + {
  732 + if (!injectedTransformers.contains(modTransformer))
704 { 733 {
705 - if (!injectedTransformers.contains(modTransformer)) 734 + List<Throwable> throwables = transformerManager.getTransformerStartupErrors(modTransformer);
  735 + if (throwables != null)
706 { 736 {
707 - List<Throwable> throwables = transformerManager.getTransformerStartupErrors(modTransformer);  
708 - if (throwables != null) 737 + for (Throwable th : throwables)
709 { 738 {
710 - for (Throwable th : throwables)  
711 - {  
712 - this.registerModStartupError(mod, th, true);  
713 - }  
714 - }  
715 - else  
716 - {  
717 - this.registerModStartupError(mod, new RuntimeException("Missing class transformer " + modTransformer), true); 739 + this.registerModStartupError(mod, th, true);
718 } 740 }
719 } 741 }
  742 + else
  743 + {
  744 + this.registerModStartupError(mod, new RuntimeException("Missing class transformer " + modTransformer), true);
  745 + }
720 } 746 }
721 } 747 }
722 } 748 }
@@ -765,7 +791,11 @@ public class LiteLoaderMods @@ -765,7 +791,11 @@ public class LiteLoaderMods
765 private void registerModStartupError(ModInfo<?> mod, Throwable th, boolean critical) 791 private void registerModStartupError(ModInfo<?> mod, Throwable th, boolean critical)
766 { 792 {
767 this.startupErrorCount++; 793 this.startupErrorCount++;
768 - if (critical) this.criticalErrorCount++; 794 + if (critical)
  795 + {
  796 + this.criticalErrorCount++;
  797 + }
  798 +
769 mod.registerStartupError(th); 799 mod.registerStartupError(th);
770 800
771 if (!this.loadedMods.contains(mod) && !this.disabledMods.contains(mod)) 801 if (!this.loadedMods.contains(mod) && !this.disabledMods.contains(mod))
src/main/java/com/mumfrey/liteloader/interfaces/LoadableFile.java
@@ -10,6 +10,8 @@ import java.io.IOException; @@ -10,6 +10,8 @@ import java.io.IOException;
10 import java.net.MalformedURLException; 10 import java.net.MalformedURLException;
11 import java.net.URL; 11 import java.net.URL;
12 import java.nio.charset.Charset; 12 import java.nio.charset.Charset;
  13 +import java.util.ArrayList;
  14 +import java.util.Collection;
13 import java.util.Collections; 15 import java.util.Collections;
14 import java.util.HashSet; 16 import java.util.HashSet;
15 import java.util.List; 17 import java.util.List;
@@ -97,6 +99,11 @@ public class LoadableFile extends File implements TweakContainer&lt;File&gt; @@ -97,6 +99,11 @@ public class LoadableFile extends File implements TweakContainer&lt;File&gt;
97 * Mixin config resource names 99 * Mixin config resource names
98 */ 100 */
99 protected Set<String> mixinConfigs = new HashSet<String>(); 101 protected Set<String> mixinConfigs = new HashSet<String>();
  102 +
  103 + /**
  104 + * Mixin errors
  105 + */
  106 + protected List<Throwable> mixinErrors = new ArrayList<Throwable>();
100 107
101 /** 108 /**
102 * Create a new tweak container wrapping the specified file 109 * Create a new tweak container wrapping the specified file
@@ -344,6 +351,18 @@ public class LoadableFile extends File implements TweakContainer&lt;File&gt; @@ -344,6 +351,18 @@ public class LoadableFile extends File implements TweakContainer&lt;File&gt;
344 { 351 {
345 return this.mixinConfigs; 352 return this.mixinConfigs;
346 } 353 }
  354 +
  355 + @Override
  356 + public void registerMixinError(Throwable th)
  357 + {
  358 + this.mixinErrors.add(th);
  359 + }
  360 +
  361 + @Override
  362 + public Collection<Throwable> getMixinErrors()
  363 + {
  364 + return this.mixinErrors;
  365 + }
347 366
348 @Override 367 @Override
349 public boolean hasEventTransformers() 368 public boolean hasEventTransformers()
src/main/java/com/mumfrey/liteloader/interfaces/MixinContainer.java
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 */ 5 */
6 package com.mumfrey.liteloader.interfaces; 6 package com.mumfrey.liteloader.interfaces;
7 7
  8 +import java.util.Collection;
8 import java.util.Set; 9 import java.util.Set;
9 10
10 public interface MixinContainer<L> extends Loadable<L>, Injectable 11 public interface MixinContainer<L> extends Loadable<L>, Injectable
@@ -19,5 +20,17 @@ public interface MixinContainer&lt;L&gt; extends Loadable&lt;L&gt;, Injectable @@ -19,5 +20,17 @@ public interface MixinContainer&lt;L&gt; extends Loadable&lt;L&gt;, Injectable
19 * Get this mod's list of mixin configs 20 * Get this mod's list of mixin configs
20 */ 21 */
21 public abstract Set<String> getMixinConfigs(); 22 public abstract Set<String> getMixinConfigs();
  23 +
  24 + /**
  25 + * Register a mixin error with the container
  26 + *
  27 + * @param th caught throwable
  28 + */
  29 + public abstract void registerMixinError(Throwable th);
  30 +
  31 + /**
  32 + * @return mixin errors
  33 + */
  34 + public abstract Collection<Throwable> getMixinErrors();
22 35
23 } 36 }