]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/cli/Main.java
Print detailed error messages for send failures
[signal-cli] / src / main / java / cli / Main.java
index f6b6bb7093197a9d07a02e2a0e4e54860789b440..4aec19205137e13569eb6c3a94cb46f47efddac5 100644 (file)
@@ -1,16 +1,16 @@
 /**
  * Copyright (C) 2015 AsamK
- * <p>
+ *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * <p>
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * <p>
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -21,10 +21,13 @@ import net.sourceforge.argparse4j.impl.Arguments;
 import net.sourceforge.argparse4j.inf.*;
 import org.apache.commons.io.IOUtils;
 import org.whispersystems.textsecure.api.TextSecureMessageSender;
+import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
 import org.whispersystems.textsecure.api.messages.*;
 import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage;
 import org.whispersystems.textsecure.api.push.TextSecureAddress;
 import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions;
+import org.whispersystems.textsecure.api.push.exceptions.NetworkFailureException;
+import org.whispersystems.textsecure.api.push.exceptions.UnregisteredUserException;
 import org.whispersystems.textsecure.api.util.InvalidNumberException;
 
 import java.io.File;
@@ -162,8 +165,19 @@ public class Main {
                 }
                 try {
                     messageSender.sendMessage(recipients, message);
-                } catch (IOException | EncapsulatedExceptions e) {
+                } catch (IOException e) {
                     System.out.println("Failed to send message: " + e.getMessage());
+                } catch (EncapsulatedExceptions e) {
+                    System.out.println("Failed to send (some) messages:");
+                    for (NetworkFailureException n : e.getNetworkExceptions()) {
+                        System.out.println("Network failure for \"" + n.getE164number() + "\": " + n.getMessage());
+                    }
+                    for (UnregisteredUserException n : e.getUnregisteredUserExceptions()) {
+                        System.out.println("Unregistered user \"" + n.getE164Number() + "\": " + n.getMessage());
+                    }
+                    for (UntrustedIdentityException n : e.getUntrustedIdentityExceptions()) {
+                        System.out.println("Untrusted Identity for \"" + n.getE164Number() + "\": " + n.getMessage());
+                    }
                 }
                 break;
             case "receive":