import org.asamk.signal.commands.RegistrationCommand;
import org.asamk.signal.commands.SignalCreator;
import org.asamk.signal.commands.exceptions.CommandException;
+import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
+ e.getMessage()
+ " ("
+ e.getClass().getSimpleName()
- + ")");
+ + ")", e);
}
try (var m = manager) {
command.handleCommand(ns, m);
} catch (NotRegisteredException e) {
throw new UserErrorException("User " + username + " is not registered.");
} catch (Throwable e) {
- logger.debug("Loading state file failed", e);
throw new UnexpectedErrorException("Error loading state file for user "
+ username
+ ": "
+ e.getMessage()
+ " ("
+ e.getClass().getSimpleName()
- + ")");
+ + ")", e);
}
try {
manager.checkAccountState();
} catch (IOException e) {
- throw new UnexpectedErrorException("Error while checking account " + username + ": " + e.getMessage());
+ throw new IOErrorException("Error while checking account " + username + ": " + e.getMessage(), e);
}
return manager;
}
} catch (DBusException | IOException e) {
logger.error("Dbus client failed", e);
- throw new UnexpectedErrorException("Dbus client failed");
+ throw new UnexpectedErrorException("Dbus client failed", e);
}
}
installSecurityProviderWorkaround();
// Configuring the logger needs to happen before any logger is initialized
- configureLogging(isVerbose(args));
+ final var isVerbose = isVerbose(args);
+ configureLogging(isVerbose);
var parser = App.buildArgumentParser();
new App(ns).init();
} catch (CommandException e) {
System.err.println(e.getMessage());
+ if (isVerbose && e.getCause() != null) {
+ e.getCause().printStackTrace();
+ }
status = getStatusForError(e);
}
System.exit(status);
m.addDeviceLink(new URI(ns.getString("uri")));
} catch (IOException e) {
logger.error("Add device link failed", e);
- throw new IOErrorException("Add device link failed");
+ throw new IOErrorException("Add device link failed", e);
} catch (URISyntaxException e) {
throw new UserErrorException("Device link uri has invalid format: " + e.getMessage());
} catch (InvalidKeyException e) {
logger.error("Add device link failed", e);
- throw new UnexpectedErrorException("Add device link failed.");
+ throw new UnexpectedErrorException("Add device link failed.", e);
}
}
}
} catch (NotMasterDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
} catch (IOException e) {
- throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage());
+ throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage(), e);
}
}
} catch (GroupNotFoundException e) {
logger.warn("Group not found {}: {}", groupId.toBase64(), e.getMessage());
} catch (IOException e) {
- throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage());
+ throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage(), e);
}
}
}
}
} catch (DBusException | IOException e) {
logger.error("Dbus command failed", e);
- throw new UnexpectedErrorException("Dbus command failed");
+ throw new UnexpectedErrorException("Dbus command failed", e);
}
}
signalControl.run();
} catch (DBusException | IOException e) {
logger.error("Dbus command failed", e);
- throw new UnexpectedErrorException("Dbus command failed");
+ throw new UnexpectedErrorException("Dbus command failed", e);
}
}
try {
registered = m.areUsersRegistered(new HashSet<>(ns.getList("recipient")));
} catch (IOException e) {
- logger.debug("Failed to check registered users", e);
- throw new IOErrorException("Unable to check if users are registered");
+ throw new IOErrorException("Unable to check if users are registered", e);
}
// Output
+ e.getMessage()
+ " ("
+ e.getClass().getSimpleName()
- + ")");
+ + ")", e);
} catch (DBusExecutionException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
} catch (GroupLinkNotActiveException e) {
throw new UserErrorException("Group link is not valid: " + e.getMessage());
}
} catch (TimeoutException e) {
throw new UserErrorException("Link request timed out, please try again.");
} catch (IOException e) {
- throw new IOErrorException("Link request error: " + e.getMessage());
+ throw new IOErrorException("Link request error: " + e.getMessage(), e);
} catch (UserAlreadyExists e) {
throw new UserErrorException("The user "
+ e.getUsername()
try {
devices = m.getLinkedDevices();
} catch (IOException e) {
- logger.debug("Failed to get linked devices", e);
- throw new IOErrorException("Failed to get linked devices: " + e.getMessage());
+ throw new IOErrorException("Failed to get linked devices: " + e.getMessage(), e);
}
if (outputWriter instanceof PlainTextWriter) {
public final long lastSeenTimestamp;
private JsonDevice(
- final long id,
- final String name,
- final long createdTimestamp,
- final long lastSeenTimestamp
+ final long id, final String name, final long createdTimestamp, final long lastSeenTimestamp
) {
this.id = id;
this.name = name;
+ e.getMessage()
+ " ("
+ e.getClass().getSimpleName()
- + ")");
+ + ")", e);
} catch (GroupNotFoundException e) {
throw new UserErrorException("Failed to send to group: " + e.getMessage());
} catch (LastGroupAdminException e) {
}
} catch (DBusException e) {
logger.error("Dbus client failed", e);
- throw new UnexpectedErrorException("Dbus client failed");
+ throw new UnexpectedErrorException("Dbus client failed", e);
}
while (true) {
try {
ignoreAttachments,
handler);
} catch (IOException e) {
- throw new IOErrorException("Error while receiving messages: " + e.getMessage());
+ throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
}
}
}
}
throw new UserErrorException(message);
} catch (IOException e) {
- throw new IOErrorException("Request verify error: " + e.getMessage());
+ throw new IOErrorException("Request verify error: " + e.getMessage(), e);
}
}
}
throw new UserErrorException(e.getMessage());
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
throw new UserErrorException("Failed to send to group: " + e.getMessage());
} catch (DBusExecutionException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
int deviceId = ns.getInt("device-id");
m.removeLinkedDevices(deviceId);
} catch (IOException e) {
- throw new IOErrorException("Error while removing device: " + e.getMessage());
+ throw new IOErrorException("Error while removing device: " + e.getMessage(), e);
}
}
}
try {
m.setRegistrationLockPin(Optional.absent());
} catch (UnauthenticatedResponseException e) {
- throw new UnexpectedErrorException("Remove pin failed with unauthenticated response: " + e.getMessage());
+ throw new UnexpectedErrorException("Remove pin failed with unauthenticated response: " + e.getMessage(), e);
} catch (IOException e) {
- throw new IOErrorException("Remove pin error: " + e.getMessage());
+ throw new IOErrorException("Remove pin error: " + e.getMessage(), e);
}
}
}
return;
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
ErrorUtils.handleSendMessageResults(results.getResults());
} catch (AttachmentInvalidException | IOException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new UserErrorException(e.getMessage());
}
.getSimpleName() + ")");
} catch (DBusExecutionException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
outputResult(outputWriter, timestamp);
return;
} catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send group message: " + e.getMessage());
+ throw new UnexpectedErrorException("Failed to send group message: " + e.getMessage(), e);
}
}
throw new UntrustedKeyErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
.getSimpleName() + ")");
} catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send note to self message: " + e.getMessage());
+ throw new UnexpectedErrorException("Failed to send note to self message: " + e.getMessage(), e);
}
}
.getSimpleName() + ")");
} catch (DBusExecutionException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
try {
m.sendContacts();
} catch (IOException e) {
- throw new IOErrorException("SendContacts error: " + e.getMessage());
+ throw new IOErrorException("SendContacts error: " + e.getMessage(), e);
}
}
}
throw new UserErrorException(e.getMessage());
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
throw new UserErrorException("Failed to send to group: " + e.getMessage());
} catch (DBusExecutionException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
try {
m.requestAllSyncData();
} catch (IOException e) {
- throw new IOErrorException("Request sync data error: " + e.getMessage());
+ throw new IOErrorException("Request sync data error: " + e.getMessage(), e);
}
}
}
var registrationLockPin = ns.getString("pin");
m.setRegistrationLockPin(Optional.of(registrationLockPin));
} catch (UnauthenticatedResponseException e) {
- throw new UnexpectedErrorException("Set pin error failed with unauthenticated response: " + e.getMessage());
+ throw new UnexpectedErrorException("Set pin error failed with unauthenticated response: " + e.getMessage(),
+ e);
} catch (IOException e) {
- throw new IOErrorException("Set pin error: " + e.getMessage());
+ throw new IOErrorException("Set pin error: " + e.getMessage(), e);
}
}
}
} catch (NotMasterDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
} catch (IOException e) {
- throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage());
+ throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage(), e);
}
}
} catch (GroupNotFoundException e) {
logger.warn("Unknown group id: {}", groupId);
} catch (IOException e) {
- throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage());
+ throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage(), e);
}
}
}
m.unregister();
}
} catch (IOException e) {
- throw new IOErrorException("Unregister error: " + e.getMessage());
+ throw new IOErrorException("Unregister error: " + e.getMessage(), e);
}
}
}
try {
m.updateAccountAttributes(deviceName);
} catch (IOException e) {
- throw new IOErrorException("UpdateAccount error: " + e.getMessage());
+ throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
}
}
}
m.setContactName(recipient, name);
}
} catch (IOException e) {
- throw new IOErrorException("Update contact error: " + e.getMessage());
+ throw new IOErrorException("Update contact error: " + e.getMessage(), e);
} catch (NotMasterDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
}
throw new UserErrorException(e.getMessage());
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
throw new UserErrorException("Failed to add avatar attachment for group\": " + e.getMessage());
} catch (DBusExecutionException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
+ .getSimpleName() + ")", e);
}
}
try {
m.setProfile(givenName, familyName, about, aboutEmoji, avatarFile);
} catch (IOException e) {
- throw new IOErrorException("Update profile error: " + e.getMessage());
+ throw new IOErrorException("Update profile error: " + e.getMessage(), e);
}
}
}
writer.write(Map.of("url", url));
}
} catch (IOException e) {
- throw new IOErrorException("Upload error (maybe image size too large):" + e.getMessage());
+ throw new IOErrorException("Upload error (maybe image size too large):" + e.getMessage(), e);
} catch (StickerPackInvalidException e) {
throw new UserErrorException("Invalid sticker pack: " + e.getMessage());
}
} catch (KeyBackupServicePinException e) {
throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
} catch (KeyBackupSystemNoDataException e) {
- throw new UnexpectedErrorException("Verification failed! No KBS data.");
+ throw new UnexpectedErrorException("Verification failed! No KBS data.", e);
} catch (IOException e) {
- throw new IOErrorException("Verify error: " + e.getMessage());
+ throw new IOErrorException("Verify error: " + e.getMessage(), e);
}
}
}
public CommandException(final String message) {
super(message);
}
+
+ public CommandException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
}
package org.asamk.signal.commands.exceptions;
+import java.io.IOException;
+
public final class IOErrorException extends CommandException {
- public IOErrorException(final String message) {
- super(message);
+ public IOErrorException(final String message, IOException cause) {
+ super(message, cause);
}
}
public final class UnexpectedErrorException extends CommandException {
- public UnexpectedErrorException(final String message) {
- super(message);
+ public UnexpectedErrorException(final String message, final Throwable cause) {
+ super(message, cause);
}
}
for (var error : errors) {
message.append(error).append("\n");
}
- throw new IOErrorException(message.toString());
+ throw new IOErrorException(message.toString(), null);
}
}