Skip to content

Commit

Permalink
Reduce use of printStackTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Nov 7, 2023
1 parent 4e8f0a4 commit e61f587
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/asamk/signal/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void handleMessage(MessageEnvelope envelope, Throwable exception) {
try {
sendDbusMessages(envelope);
} catch (DBusException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e61f587

Please sign in to comment.