Skip to content

Commit

Permalink
Show better error message when using addDevice on a linked device
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Aug 21, 2023
1 parent 3d13c69 commit 6d23eb3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/src/main/java/org/asamk/signal/manager/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static boolean isSignalClientAvailable() {

void removeLinkedDevices(int deviceId) throws IOException;

void addDeviceLink(DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException;
void addDeviceLink(DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException, NotPrimaryDeviceException;

void setRegistrationLockPin(Optional<String> pin) throws IOException, NotPrimaryDeviceException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ public void removeLinkedDevices(int deviceId) throws IOException {
}

@Override
public void addDeviceLink(DeviceLinkUrl linkUrl) throws IOException, InvalidDeviceLinkException {
public void addDeviceLink(DeviceLinkUrl linkUrl) throws IOException, InvalidDeviceLinkException, NotPrimaryDeviceException {
if (!account.isPrimaryDevice()) {
throw new NotPrimaryDeviceException();
}
context.getAccountHelper().addDevice(linkUrl);
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/asamk/signal/commands/AddDeviceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
import org.asamk.signal.output.OutputWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -49,11 +50,13 @@ public void handleCommand(
var deviceLinkUrl = DeviceLinkUrl.parseDeviceLinkUri(linkUri);
m.addDeviceLink(deviceLinkUrl);
} catch (IOException e) {
logger.error("Add device link failed", e);
logger.error("Add device link failed: {}", e.getMessage());
throw new IOErrorException("Add device link failed", e);
} catch (InvalidDeviceLinkException e) {
logger.error("Add device link failed", e);
throw new UserErrorException("Add device link failed.", e);
logger.error("Invalid device link");
throw new UserErrorException("Invalid device link", e);
} catch (NotPrimaryDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void handleCommand(
var stickerPackUrl = StickerPackUrl.fromUri(stickerUri);
m.installStickerPack(stickerPackUrl);
} catch (IOException e) {
logger.error("Install sticker pack failed", e);
logger.error("Install sticker pack failed: {}", e.getMessage());
throw new IOErrorException("Install sticker pack failed", e);
} catch (StickerPackUrl.InvalidStickerPackLinkException e) {
logger.error("Invalid sticker pack link", e);
logger.error("Invalid sticker pack link");
throw new UserErrorException("Invalid sticker pack link", e);
}
}
Expand Down

0 comments on commit 6d23eb3

Please sign in to comment.