Skip to content

Commit

Permalink
Expose mod id in errors
Browse files Browse the repository at this point in the history
Co-authored-by: shedaniel <[email protected]>
  • Loading branch information
sfPlayer1 and shedaniel committed Aug 22, 2021
1 parent a5743a7 commit 6bb09f8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
44 changes: 44 additions & 0 deletions src/main/java/org/spongepowered/asm/mixin/FabricUtil.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,18 @@ public void postInject() {
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));
}
}

Expand Down Expand Up @@ -753,7 +753,7 @@ public static String getInjectorPrefix(AnnotationNode annotation) {
}

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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public String getLogMessage(String context, InvalidMixinException ex, IMixinInfo
}

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());
}

}
Expand Down Expand Up @@ -542,7 +542,7 @@ public void onInit(MixinInfo mixin) {
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);
}
}

Expand All @@ -569,7 +569,7 @@ public void onInit(MixinInfo mixin) {
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);
}
}

Expand Down Expand Up @@ -611,6 +611,7 @@ private void handleMixinError(String context, InvalidMixinException ex, MixinEnv
.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())
Expand Down

0 comments on commit 6bb09f8

Please sign in to comment.