Reduce use of printStackTrace

This commit is contained in:
AsamK 2023-11-07 09:28:29 +01:00
parent 4e8f0a41c7
commit e61f587bfc
4 changed files with 19 additions and 15 deletions

View file

@ -62,11 +62,11 @@ public class Main {
} catch (CommandException e) { } catch (CommandException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
if (verboseLevel > 0 && e.getCause() != null) { if (verboseLevel > 0 && e.getCause() != null) {
e.getCause().printStackTrace(); e.getCause().printStackTrace(System.err);
} }
status = getStatusForError(e); status = getStatusForError(e);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace(System.err);
status = 2; status = 2;
} }
System.exit(status); System.exit(status);

View file

@ -948,7 +948,7 @@ public class DbusManagerImpl implements Manager {
}; };
connection.addSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler); connection.addSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
} catch (DBusException e) { } catch (DBusException e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
signal.subscribeReceive(); signal.subscribeReceive();
} }
@ -968,7 +968,7 @@ public class DbusManagerImpl implements Manager {
connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler); connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler);
connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler); connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
} catch (DBusException e) { } catch (DBusException e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
} }

View file

@ -30,7 +30,7 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
try { try {
sendDbusMessages(envelope); sendDbusMessages(envelope);
} catch (DBusException e) { } catch (DBusException e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
} }

View file

@ -14,6 +14,8 @@ import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.UserAlreadyExistsException; import org.asamk.signal.manager.api.UserAlreadyExistsException;
import org.freedesktop.dbus.DBusPath; import org.freedesktop.dbus.DBusPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -24,6 +26,7 @@ import java.util.concurrent.TimeoutException;
public class DbusSignalControlImpl implements org.asamk.SignalControl { public class DbusSignalControlImpl implements org.asamk.SignalControl {
private final static Logger logger = LoggerFactory.getLogger(DbusSignalControlImpl.class);
private final MultiAccountManager c; private final MultiAccountManager c;
private final String objectPath; private final String objectPath;
@ -101,20 +104,21 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
@Override @Override
public String link(final String newDeviceName) throws Error.Failure { public String link(final String newDeviceName) throws Error.Failure {
final URI deviceLinkUri;
try { try {
final URI deviceLinkUri = c.getNewProvisioningDeviceLinkUri(); 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();
} catch (TimeoutException | IOException e) { } catch (TimeoutException | IOException e) {
throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage()); 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 @Override