Handle UnsupportedOperationException in daemon command

This commit is contained in:
AsamK 2022-02-20 10:02:15 +01:00
parent 69fe3986cf
commit 1ffb6d6907

View file

@ -10,6 +10,7 @@ import org.asamk.signal.ReceiveMessageHandler;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.dbus.DbusSignalControlImpl; import org.asamk.signal.dbus.DbusSignalControlImpl;
import org.asamk.signal.dbus.DbusSignalImpl; import org.asamk.signal.dbus.DbusSignalImpl;
import org.asamk.signal.json.JsonReceiveMessageHandler; import org.asamk.signal.json.JsonReceiveMessageHandler;
@ -282,7 +283,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
private void runDbusSingleAccount( private void runDbusSingleAccount(
final Manager m, final boolean isDbusSystem, final boolean noReceiveOnStart final Manager m, final boolean isDbusSystem, final boolean noReceiveOnStart
) throws UnexpectedErrorException { ) throws CommandException {
runDbus(isDbusSystem, (conn, objectPath) -> { runDbus(isDbusSystem, (conn, objectPath) -> {
try { try {
exportDbusObject(conn, objectPath, m, noReceiveOnStart).join(); exportDbusObject(conn, objectPath, m, noReceiveOnStart).join();
@ -293,7 +294,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
private void runDbusMultiAccount( private void runDbusMultiAccount(
final MultiAccountManager c, final boolean noReceiveOnStart, final boolean isDbusSystem final MultiAccountManager c, final boolean noReceiveOnStart, final boolean isDbusSystem
) throws UnexpectedErrorException { ) throws CommandException {
runDbus(isDbusSystem, (connection, objectPath) -> { runDbus(isDbusSystem, (connection, objectPath) -> {
final var signalControl = new DbusSignalControlImpl(c, objectPath); final var signalControl = new DbusSignalControlImpl(c, objectPath);
connection.exportObject(signalControl); connection.exportObject(signalControl);
@ -332,7 +333,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
private void runDbus( private void runDbus(
final boolean isDbusSystem, DbusRunner dbusRunner final boolean isDbusSystem, DbusRunner dbusRunner
) throws UnexpectedErrorException { ) throws CommandException {
DBusConnection.DBusBusType busType; DBusConnection.DBusBusType busType;
if (isDbusSystem) { if (isDbusSystem) {
busType = DBusConnection.DBusBusType.SYSTEM; busType = DBusConnection.DBusBusType.SYSTEM;
@ -345,6 +346,8 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
dbusRunner.run(conn, DbusConfig.getObjectPath()); dbusRunner.run(conn, DbusConfig.getObjectPath());
} catch (DBusException e) { } catch (DBusException e) {
throw new UnexpectedErrorException("Dbus command failed: " + e.getMessage(), e); throw new UnexpectedErrorException("Dbus command failed: " + e.getMessage(), e);
} catch (UnsupportedOperationException e) {
throw new UserErrorException("Failed to connect to Dbus: " + e.getMessage(), e);
} }
try { try {