import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
+import org.asamk.signal.commands.exceptions.RateLimitErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
} catch (CommandException e) {
System.err.println(e.getMessage());
if (verboseLevel > 0 && e.getCause() != null) {
- e.getCause().printStackTrace();
+ e.getCause().printStackTrace(System.err);
}
status = getStatusForError(e);
} catch (Throwable e) {
- e.printStackTrace();
+ e.printStackTrace(System.err);
status = 2;
}
System.exit(status);
}
private static int getStatusForError(final CommandException e) {
- if (e instanceof UserErrorException) {
- return 1;
- } else if (e instanceof UnexpectedErrorException) {
- return 2;
- } else if (e instanceof IOErrorException) {
- return 3;
- } else if (e instanceof UntrustedKeyErrorException) {
- return 4;
- } else {
- return 2;
- }
+ return switch (e) {
+ case UserErrorException userErrorException -> 1;
+ case UnexpectedErrorException unexpectedErrorException -> 2;
+ case IOErrorException ioErrorException -> 3;
+ case UntrustedKeyErrorException untrustedKeyErrorException -> 4;
+ case RateLimitErrorException rateLimitErrorException -> 5;
+ case null -> 2;
+ };
}
}