Commit 61eeff17a74612380366180c0126460057d961fe
1 parent
61c45ce8
Catch and report mixin registration errors as critical errors in the GUI
Showing
5 changed files
with
91 additions
and
18 deletions
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
| @@ -121,7 +121,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator | @@ -121,7 +121,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator | ||
| 121 | private final FastIterableDeque<EnumerationObserver> observers = new HandlerList<EnumerationObserver>(EnumerationObserver.class); | 121 | private final FastIterableDeque<EnumerationObserver> observers = new HandlerList<EnumerationObserver>(EnumerationObserver.class); |
| 122 | 122 | ||
| 123 | protected EnumeratorState state = EnumeratorState.INIT; | 123 | protected EnumeratorState state = EnumeratorState.INIT; |
| 124 | - | 124 | + |
| 125 | /** | 125 | /** |
| 126 | * @param environment | 126 | * @param environment |
| 127 | * @param properties | 127 | * @param properties |
| @@ -143,7 +143,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator | @@ -143,7 +143,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator | ||
| 143 | // Initialise the shared mod list if we haven't already | 143 | // Initialise the shared mod list if we haven't already |
| 144 | this.getSharedModList(); | 144 | this.getSharedModList(); |
| 145 | } | 145 | } |
| 146 | - | 146 | + |
| 147 | /** | 147 | /** |
| 148 | * @param environment | 148 | * @param environment |
| 149 | */ | 149 | */ |
| @@ -664,7 +664,15 @@ public class LiteLoaderEnumerator implements LoaderEnumerator | @@ -664,7 +664,15 @@ public class LiteLoaderEnumerator implements LoaderEnumerator | ||
| 664 | if (config.endsWith(".json")) | 664 | if (config.endsWith(".json")) |
| 665 | { | 665 | { |
| 666 | LiteLoaderLogger.info(Verbosity.REDUCED, "Registering mixin config %s for %s", config, container.getName()); | 666 | LiteLoaderLogger.info(Verbosity.REDUCED, "Registering mixin config %s for %s", config, container.getName()); |
| 667 | - Mixins.addConfiguration(config); | 667 | + try |
| 668 | + { | ||
| 669 | + Mixins.addConfiguration(config); | ||
| 670 | + } | ||
| 671 | + catch (Throwable th) | ||
| 672 | + { | ||
| 673 | + LiteLoaderLogger.severe(th, "Error registering mixin config %s for %s", config, container); | ||
| 674 | + container.registerMixinError(th); | ||
| 675 | + } | ||
| 668 | } | 676 | } |
| 669 | else if (config.contains(".json@")) | 677 | else if (config.contains(".json@")) |
| 670 | { | 678 | { |
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<File> | @@ -97,6 +99,11 @@ public class LoadableFile extends File implements TweakContainer<File> | ||
| 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<File> | @@ -344,6 +351,18 @@ public class LoadableFile extends File implements TweakContainer<File> | ||
| 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<L> extends Loadable<L>, Injectable | @@ -19,5 +20,17 @@ public interface MixinContainer<L> extends Loadable<L>, 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 | } |