Fix error handling of invalid commandline options

This commit is contained in:
crschnick 2024-01-03 18:15:06 +00:00
parent 06544d31e1
commit 0070a08109
2 changed files with 16 additions and 5 deletions

View file

@ -118,7 +118,11 @@ public class SentryErrorHandler implements ErrorHandler {
return copy;
} catch (Exception e) {
if (AppLogs.get() != null) AppLogs.get().logException("Unable to adjust exception", e);
// This can fail for example when the underlying exception is not serializable
// and comes from some third party library
if (AppLogs.get() != null) {
AppLogs.get().logException("Unable to adjust exception", e);
}
return throwable;
}
}

View file

@ -47,14 +47,14 @@ public class LauncherCommand implements Callable<Integer> {
var cmd = new CommandLine(new LauncherCommand());
cmd.setExecutionExceptionHandler((ex, commandLine, parseResult) -> {
var event = ErrorEvent.fromThrowable("Launcher command error occurred", ex).term().build();
var event = ErrorEvent.fromThrowable(ex).term().build();
// Print error in case we launched from the command-line
new LogErrorHandler().handle(event);
event.handle();
return 1;
});
cmd.setParameterExceptionHandler((ex, args1) -> {
var event = ErrorEvent.fromThrowable("Launcher parameter error occurred", ex).term().build();
var event = ErrorEvent.fromThrowable(ex).term().build();
// Print error in case we launched from the command-line
new LogErrorHandler().handle(event);
event.handle();
@ -65,8 +65,15 @@ public class LauncherCommand implements Callable<Integer> {
cmd.setOut(new PrintWriter(AppLogs.get().getOriginalSysOut()));
cmd.setErr(new PrintWriter(AppLogs.get().getOriginalSysErr()));
try {
cmd.parseArgs(args);
cmd.execute(args);
} catch (Throwable t) {
var e = ErrorEvent.fromThrowable(t).term().build();
// Print error in case we launched from the command-line
new LogErrorHandler().handle(e);
e.handle();
}
}
private void checkStart() {