Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit e92de09

Browse files
Clean up stacktrace for unimplemented class / method / field errors. (#138)
* Clean up stacktrace for unimplemented class / method / field errors. * Prettify BootstrapMethodErrors and add more information
1 parent 37e35c3 commit e92de09

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ public void onInitialize() {
108108
error = new PatchworkInitializationException("Failed to construct Patchwork mods");
109109
}
110110

111+
Throwable checked;
112+
113+
if (t instanceof BootstrapMethodError) {
114+
checked = t.getCause();
115+
} else {
116+
checked = t;
117+
}
118+
119+
if (checked instanceof NoClassDefFoundError || checked instanceof NoSuchMethodError || checked instanceof NoSuchFieldError) {
120+
final String unDefinedClass = checked.getMessage().substring(checked.getMessage().lastIndexOf(' ') + 1).replace('/', '.');
121+
String type;
122+
123+
if (checked instanceof NoClassDefFoundError) {
124+
type = "class";
125+
} else if (checked instanceof NoSuchMethodError) {
126+
type = "method";
127+
} else {
128+
type = "field";
129+
}
130+
131+
if (unDefinedClass.startsWith("net.minecraft.") || (unDefinedClass.startsWith("net.minecraftforge.") && !unDefinedClass.startsWith("net.minecraftforge.lex."))) {
132+
throw new PatchworkInitializationException("Patchwork mod " + initializer.getModId() + " tried to access an unimplemented " + type + ".", t);
133+
} else {
134+
throw new PatchworkInitializationException("Patchwork mod " + initializer.getModId() + " tried to access a missing " + type + " from a missing and undeclared, or outdated dependency.", t);
135+
}
136+
}
137+
111138
error.addSuppressed(t);
112139
}
113140

0 commit comments

Comments
 (0)