From 6bb09f835e51cef258d1ee53cbc16c0f9ab9970b Mon Sep 17 00:00:00 2001 From: Player Date: Mon, 12 Jul 2021 17:27:25 +0200 Subject: [PATCH] Expose mod id in errors Co-authored-by: shedaniel --- .../spongepowered/asm/mixin/FabricUtil.java | 44 +++++++++++++++++++ .../mixin/injection/struct/InjectionInfo.java | 14 +++--- .../asm/mixin/transformer/MixinProcessor.java | 7 +-- 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/spongepowered/asm/mixin/FabricUtil.java diff --git a/src/main/java/org/spongepowered/asm/mixin/FabricUtil.java b/src/main/java/org/spongepowered/asm/mixin/FabricUtil.java new file mode 100644 index 00000000..2cd1d5c7 --- /dev/null +++ b/src/main/java/org/spongepowered/asm/mixin/FabricUtil.java @@ -0,0 +1,44 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.spongepowered.asm.mixin; + +import org.spongepowered.asm.mixin.extensibility.IMixinConfig; + +public final class FabricUtil { + private static final String KEY_MOD_ID = "fabric-modId"; + + public static String getModId(IMixinConfig config) { + return getDecoration(config, KEY_MOD_ID, "(unknown)"); + } + + public static String getModId(ISelectorContext context) { + return getDecoration(getConfig(context), KEY_MOD_ID, "(unknown)"); + } + + private static T getDecoration(IMixinConfig config, String key, T defaultValue) { + return config.hasDecoration(key) ? config.getDecoration(key) : defaultValue; + } +} diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java index bb686fb5..44699e05 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java @@ -460,18 +460,18 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC String extraInfo = this.getDynamicInfo() + this.getMessages(); if ((this.mixin.getOption(Option.DEBUG_INJECTORS) && this.injectedCallbackCount < this.expectedCallbackCount)) { throw new InvalidInjectionException(this, - String.format("Injection validation failed: %s %s%s in %s expected %d invocation(s) but %d succeeded. Scanned %d target(s). %s%s", - description, this.methodName, this.method.desc, this.mixin, this.expectedCallbackCount, this.injectedCallbackCount, + String.format("Injection validation failed: %s %s%s in %s from mod %s expected %d invocation(s) but %d succeeded. Scanned %d target(s). %s%s", + description, this.methodName, this.method.desc, this.mixin, org.spongepowered.asm.mixin.FabricUtil.getModId(this), this.expectedCallbackCount, this.injectedCallbackCount, this.targetCount, refMapStatus, extraInfo)); } else if (this.injectedCallbackCount < this.requiredCallbackCount) { throw new InjectionError( - String.format("Critical injection failure: %s %s%s in %s failed injection check, (%d/%d) succeeded. Scanned %d target(s). %s%s", - description, this.methodName, this.method.desc, this.mixin, this.injectedCallbackCount, this.requiredCallbackCount, + String.format("Critical injection failure: %s %s%s in %s from mod %s failed injection check, (%d/%d) succeeded. Scanned %d target(s). %s%s", + description, this.methodName, this.method.desc, this.mixin, org.spongepowered.asm.mixin.FabricUtil.getModId(this), this.injectedCallbackCount, this.requiredCallbackCount, this.targetCount, refMapStatus, extraInfo)); } else if (this.injectedCallbackCount > this.maxCallbackCount) { throw new InjectionError( - String.format("Critical injection failure: %s %s%s in %s failed injection check, %d succeeded of %d allowed.%s", - description, this.methodName, this.method.desc, this.mixin, this.injectedCallbackCount, this.maxCallbackCount, extraInfo)); + String.format("Critical injection failure: %s %s%s in %s from mod %s failed injection check, %d succeeded of %d allowed.%s", + description, this.methodName, this.method.desc, this.mixin, org.spongepowered.asm.mixin.FabricUtil.getModId(this), this.injectedCallbackCount, this.maxCallbackCount, extraInfo)); } } @@ -753,7 +753,7 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC } static String describeInjector(IMixinContext mixin, AnnotationNode annotation, MethodNode method) { - return String.format("%s->@%s::%s%s", mixin.toString(), Annotations.getSimpleName(annotation), MethodNodeEx.getName(method), method.desc); + return String.format("%s->@%s::%s%s from mod %s", mixin.toString(), Annotations.getSimpleName(annotation), MethodNodeEx.getName(method), method.desc, org.spongepowered.asm.mixin.FabricUtil.getModId(mixin.getMixin().getConfig())); } /** diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java index 32f1c08c..d1c46b84 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java @@ -134,7 +134,7 @@ class MixinProcessor { } public String getErrorMessage(IMixinInfo mixin, IMixinConfig config, Phase phase) { - return String.format("Mixin [%s] from phase [%s] in config [%s] FAILED during %s", mixin, phase, config, this.name()); + return String.format("Mixin [%s] from phase [%s] in config [%s] from mod [%s] FAILED during %s", mixin, phase, config, org.spongepowered.asm.mixin.FabricUtil.getModId(config), this.name()); } } @@ -542,7 +542,7 @@ class MixinProcessor { this.handleMixinPrepareError(config, ex, environment); } catch (Exception ex) { String message = ex.getMessage(); - MixinProcessor.logger.error("Error encountered whilst initialising mixin config '" + config.getName() + "': " + message, ex); + MixinProcessor.logger.error("Error encountered whilst initialising mixin config '" + config.getName() + "' from mod '"+org.spongepowered.asm.mixin.FabricUtil.getModId(config)+"': " + message, ex); } } @@ -569,7 +569,7 @@ class MixinProcessor { this.handleMixinPrepareError(config, ex, environment); } catch (Exception ex) { String message = ex.getMessage(); - MixinProcessor.logger.error("Error encountered during mixin config postInit step'" + config.getName() + "': " + message, ex); + MixinProcessor.logger.error("Error encountered during mixin config postInit step '" + config.getName() + "' from mod '"+org.spongepowered.asm.mixin.FabricUtil.getModId(config)+ "': " + message, ex); } } @@ -611,6 +611,7 @@ class MixinProcessor { .kv("Action", errorPhase.name()) .kv("Mixin", mixin.getClassName()) .kv("Config", config.getName()) + .kv("ModId", org.spongepowered.asm.mixin.FabricUtil.getModId(config)) .kv("Phase", phase) .hr('-') .add(" %s", ex.getClass().getName())