Do not print stacktrace on known exceptions

This commit is contained in:
yushijinhun 2018-10-04 16:25:51 +08:00
parent 422236f365
commit e002f5f167
No known key found for this signature in database
GPG key ID: 5BC167F73EA558E4
3 changed files with 32 additions and 6 deletions

View file

@ -67,7 +67,7 @@ public final class AuthlibInjector {
private static AtomicBoolean booted = new AtomicBoolean(false);
public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) {
public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) throws InjectorInitializationException {
if (!booted.compareAndSet(false, true)) {
Logging.LAUNCH.info("Already started, skipping");
return;
@ -79,7 +79,8 @@ public final class AuthlibInjector {
if (optionalConfig.isPresent()) {
transformerRegistry.accept(createTransformer(optionalConfig.get()));
} else {
Logging.LAUNCH.warning("No config available");
Logging.LAUNCH.severe("No config available");
throw new InjectorInitializationException();
}
}
@ -107,7 +108,7 @@ public final class AuthlibInjector {
metadataResponse = asString(getURL(apiRoot));
} catch (IOException e) {
Logging.CONFIG.severe("Failed to fetch metadata: " + e);
throw new UncheckedIOException(e);
throw new InjectorInitializationException(e);
}
} else {
@ -118,7 +119,7 @@ public final class AuthlibInjector {
Logging.CONFIG.severe("Unable to decode metadata: " + e + "\n"
+ "Encoded metadata:\n"
+ prefetched.get());
throw e;
throw new InjectorInitializationException(e);
}
}
@ -128,10 +129,10 @@ public final class AuthlibInjector {
try {
configuration = YggdrasilConfiguration.parse(apiRoot, metadataResponse);
} catch (UncheckedIOException e) {
Logging.CONFIG.severe("Unable to parse metadata: " + e + "\n"
Logging.CONFIG.severe("Unable to parse metadata: " + e.getCause() + "\n"
+ "Raw metadata:\n"
+ metadataResponse);
throw e;
throw new InjectorInitializationException(e);
}
Logging.CONFIG.fine("Parsed metadata: " + configuration);
return of(configuration);

View file

@ -0,0 +1,19 @@
package moe.yushi.authlibinjector;
public class InjectorInitializationException extends RuntimeException {
public InjectorInitializationException() {
}
public InjectorInitializationException(String message, Throwable cause) {
super(message, cause);
}
public InjectorInitializationException(String message) {
super(message);
}
public InjectorInitializationException(Throwable cause) {
super(cause);
}
}

View file

@ -6,6 +6,8 @@ import static moe.yushi.authlibinjector.AuthlibInjector.nonTransformablePackages
import java.lang.instrument.Instrumentation;
import java.util.Arrays;
import java.util.logging.Level;
import moe.yushi.authlibinjector.InjectorInitializationException;
import moe.yushi.authlibinjector.util.Logging;
public class AuthlibInjectorPremain {
@ -17,6 +19,8 @@ public class AuthlibInjectorPremain {
public static void premain(String arg, Instrumentation instrumentation) {
try {
initInjector(arg, instrumentation, false);
} catch (InjectorInitializationException e) {
System.exit(1);
} catch (Throwable e) {
Logging.LAUNCH.log(Level.SEVERE, "An exception has occurred, exiting", e);
System.exit(1);
@ -27,6 +31,8 @@ public class AuthlibInjectorPremain {
try {
Logging.LAUNCH.info("Launched from agentmain");
initInjector(arg, instrumentation, true);
} catch (InjectorInitializationException e) {
;
} catch (Throwable e) {
Logging.LAUNCH.log(Level.SEVERE, "An exception has occurred", e);
}