From e61f587bfc8f5557587d8c6cd54efcaf6631fdce Mon Sep 17 00:00:00 2001 From: AsamK Date: Tue, 7 Nov 2023 09:28:29 +0100 Subject: [PATCH] Reduce use of printStackTrace --- src/main/java/org/asamk/signal/Main.java | 4 ++-- .../asamk/signal/dbus/DbusManagerImpl.java | 4 ++-- .../dbus/DbusReceiveMessageHandler.java | 2 +- .../signal/dbus/DbusSignalControlImpl.java | 24 +++++++++++-------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/asamk/signal/Main.java b/src/main/java/org/asamk/signal/Main.java index 2b805b685e..1e05206d81 100644 --- a/src/main/java/org/asamk/signal/Main.java +++ b/src/main/java/org/asamk/signal/Main.java @@ -62,11 +62,11 @@ public static void main(String[] args) { } 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); diff --git a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java index 49aa0e2777..e9fc3f9cd1 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java @@ -948,7 +948,7 @@ private void installMessageHandlers() { }; connection.addSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler); } catch (DBusException e) { - e.printStackTrace(); + throw new RuntimeException(e); } signal.subscribeReceive(); } @@ -968,7 +968,7 @@ private void uninstallMessageHandlers() { connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler); connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler); } catch (DBusException e) { - e.printStackTrace(); + throw new RuntimeException(e); } } diff --git a/src/main/java/org/asamk/signal/dbus/DbusReceiveMessageHandler.java b/src/main/java/org/asamk/signal/dbus/DbusReceiveMessageHandler.java index 0ce114cd59..29f4a4c9e0 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusReceiveMessageHandler.java +++ b/src/main/java/org/asamk/signal/dbus/DbusReceiveMessageHandler.java @@ -30,7 +30,7 @@ public void handleMessage(MessageEnvelope envelope, Throwable exception) { try { sendDbusMessages(envelope); } catch (DBusException e) { - e.printStackTrace(); + throw new RuntimeException(e); } } diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java index 7452eaee3a..86ad6c1e71 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java @@ -14,6 +14,8 @@ import org.asamk.signal.manager.api.RateLimitException; import org.asamk.signal.manager.api.UserAlreadyExistsException; import org.freedesktop.dbus.DBusPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.URI; @@ -24,6 +26,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl { + private final static Logger logger = LoggerFactory.getLogger(DbusSignalControlImpl.class); private final MultiAccountManager c; private final String objectPath; @@ -101,20 +104,21 @@ public void verifyWithPin( @Override public String link(final String newDeviceName) throws Error.Failure { + final URI deviceLinkUri; try { - final URI deviceLinkUri = c.getNewProvisioningDeviceLinkUri(); - Thread.ofPlatform().name("dbus-link").start(() -> { - final ProvisioningManager provisioningManager = c.getProvisioningManagerFor(deviceLinkUri); - try { - provisioningManager.finishDeviceLink(newDeviceName); - } catch (IOException | TimeoutException | UserAlreadyExistsException e) { - e.printStackTrace(); - } - }); - return deviceLinkUri.toString(); + deviceLinkUri = c.getNewProvisioningDeviceLinkUri(); } catch (TimeoutException | IOException e) { throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage()); } + Thread.ofPlatform().name("dbus-link").start(() -> { + final ProvisioningManager provisioningManager = c.getProvisioningManagerFor(deviceLinkUri); + try { + provisioningManager.finishDeviceLink(newDeviceName); + } catch (IOException | TimeoutException | UserAlreadyExistsException e) { + logger.warn("Failed to finish linking", e); + } + }); + return deviceLinkUri.toString(); } @Override