diff --git a/src/main/java/net/raphimc/viaproxy/ViaProxy.java b/src/main/java/net/raphimc/viaproxy/ViaProxy.java index 11ba555..d0b6ffb 100644 --- a/src/main/java/net/raphimc/viaproxy/ViaProxy.java +++ b/src/main/java/net/raphimc/viaproxy/ViaProxy.java @@ -53,6 +53,7 @@ import net.raphimc.viaproxy.util.logging.Logger; import javax.swing.*; import java.awt.*; +import java.io.IOException; import java.lang.instrument.Instrumentation; public class ViaProxy { @@ -92,7 +93,7 @@ public class ViaProxy { } } - public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException { + public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException { Logger.setup(); final boolean hasUI = args.length == 0 && !GraphicsEnvironment.isHeadless(); ConsoleHandler.hookConsole(); @@ -142,12 +143,7 @@ public class ViaProxy { return; } - try { - Options.parse(args); - } catch (Throwable t) { - Logger.LOGGER.fatal("[" + t.getClass().getSimpleName() + "] " + t.getMessage()); - System.exit(0); - } + Options.parse(args); if (System.getProperty("skipUpdateCheck") == null) { updateCheckThread.start(); diff --git a/src/main/java/net/raphimc/viaproxy/cli/options/Options.java b/src/main/java/net/raphimc/viaproxy/cli/options/Options.java index fd8cccb..d569bb4 100644 --- a/src/main/java/net/raphimc/viaproxy/cli/options/Options.java +++ b/src/main/java/net/raphimc/viaproxy/cli/options/Options.java @@ -17,6 +17,7 @@ */ package net.raphimc.viaproxy.cli.options; +import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; import joptsimple.OptionSpec; @@ -82,11 +83,20 @@ public class Options { final OptionSpec legacyClientPassthrough = parser.acceptsAll(asList("legacy_client_passthrough", "legacy_passthrough"), "Allow <= 1.6.4 clients to connect to the backend server (No protocol translation)"); PluginManager.EVENT_MANAGER.call(new PreOptionsParseEvent(parser)); - final OptionSet options = parser.parse(args); + final OptionSet options; + try { + options = parser.parse(args); + } catch (OptionException e) { + Logger.LOGGER.error("Error parsing options: " + e.getMessage()); + parser.formatHelpWith(new BetterHelpFormatter()); + parser.printHelpOn(Logger.SYSOUT); + System.exit(1); + return; + } if (options.has(help)) { parser.formatHelpWith(new BetterHelpFormatter()); parser.printHelpOn(Logger.SYSOUT); - System.exit(0); + System.exit(1); } BIND_ADDRESS = options.valueOf(bindAddress);