Expose mod id in errors

Co-authored-by: shedaniel <[email protected]>
This commit is contained in:
Playerandshedaniel authored and Player committed 2021-08-22 22:06:29 +00:00
1 parent a5743a740a
commit 6bb09f835e
3 files changed
+55 -10

No files matched your search

@@ -0,0 +1,44 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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> T getDecoration(IMixinConfig config, String key, T defaultValue) {
return config.hasDecoration(key) ? config.getDecoration(key) : defaultValue;
}
}
@@ -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()));
}
/**
@@ -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())