From ce89727f31e45c6d75be432e7d9ba438e7bd410e Mon Sep 17 00:00:00 2001 From: famous1622 <8428080+famous1622@users.noreply.github.com> Date: Tue, 21 Jul 2020 14:39:52 -0400 Subject: [PATCH 1/2] Clean up stacktrace for unimplemented class / method / field errors. --- .../src/main/java/net/patchworkmc/impl/Patchwork.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java b/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java index 6a0d999b..897a0343 100644 --- a/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java +++ b/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java @@ -107,6 +107,10 @@ public void onInitialize() { error = new PatchworkInitializationException("Failed to construct Patchwork mods"); } + if (t instanceof NoClassDefFoundError || t instanceof NoSuchMethodError || t instanceof NoSuchFieldError) { + throw new PatchworkInitializationException("Patchwork mod "+ initializer.getModId() + " tried to access an unimplemented class or class member.", t); + } + error.addSuppressed(t); } From 678d602f75133f88a0d9f0fc5de3bf752ffdd032 Mon Sep 17 00:00:00 2001 From: famous1622 <8428080+famous1622@users.noreply.github.com> Date: Thu, 30 Jul 2020 17:49:33 -0400 Subject: [PATCH 2/2] Prettify BootstrapMethodErrors and add more information --- .../java/net/patchworkmc/impl/Patchwork.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java b/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java index 897a0343..5bc276cd 100644 --- a/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java +++ b/patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java @@ -107,8 +107,31 @@ public void onInitialize() { error = new PatchworkInitializationException("Failed to construct Patchwork mods"); } - if (t instanceof NoClassDefFoundError || t instanceof NoSuchMethodError || t instanceof NoSuchFieldError) { - throw new PatchworkInitializationException("Patchwork mod "+ initializer.getModId() + " tried to access an unimplemented class or class member.", t); + Throwable checked; + + if (t instanceof BootstrapMethodError) { + checked = t.getCause(); + } else { + checked = t; + } + + if (checked instanceof NoClassDefFoundError || checked instanceof NoSuchMethodError || checked instanceof NoSuchFieldError) { + final String unDefinedClass = checked.getMessage().substring(checked.getMessage().lastIndexOf(' ') + 1).replace('/', '.'); + String type; + + if (checked instanceof NoClassDefFoundError) { + type = "class"; + } else if (checked instanceof NoSuchMethodError) { + type = "method"; + } else { + type = "field"; + } + + if (unDefinedClass.startsWith("net.minecraft.") || (unDefinedClass.startsWith("net.minecraftforge.") && !unDefinedClass.startsWith("net.minecraftforge.lex."))) { + throw new PatchworkInitializationException("Patchwork mod " + initializer.getModId() + " tried to access an unimplemented " + type + ".", t); + } else { + throw new PatchworkInitializationException("Patchwork mod " + initializer.getModId() + " tried to access a missing " + type + " from a missing and undeclared, or outdated dependency.", t); + } } error.addSuppressed(t);