]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/Main.java
Remove now unnecessary try/catch
[signal-cli] / src / main / java / org / asamk / signal / Main.java
index 3da4fbcba6459e2628d687d8e6d240c8bf4c33e9..1e05206d81b290930a929badbe13bd4efdf2b4c5 100644 (file)
@@ -24,9 +24,11 @@ import net.sourceforge.argparse4j.inf.Namespace;
 
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
 
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
+import org.asamk.signal.commands.exceptions.RateLimitErrorException;
 import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
 import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
 import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
 import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
+import org.asamk.signal.logging.LogConfigurator;
 import org.asamk.signal.manager.ManagerLogger;
 import org.asamk.signal.util.SecurityProvider;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.asamk.signal.manager.ManagerLogger;
 import org.asamk.signal.util.SecurityProvider;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
@@ -47,7 +49,8 @@ public class Main {
         final var nsLog = parseArgs(args);
         final var verboseLevel = nsLog == null ? 0 : nsLog.getInt("verbose");
         final var logFile = nsLog == null ? null : nsLog.<File>get("log-file");
         final var nsLog = parseArgs(args);
         final var verboseLevel = nsLog == null ? 0 : nsLog.getInt("verbose");
         final var logFile = nsLog == null ? null : nsLog.<File>get("log-file");
-        configureLogging(verboseLevel, logFile);
+        final var scrubLog = nsLog != null && nsLog.getBoolean("scrub-log");
+        configureLogging(verboseLevel, logFile, scrubLog);
 
         var parser = App.buildArgumentParser();
 
 
         var parser = App.buildArgumentParser();
 
@@ -59,11 +62,11 @@ public class Main {
         } catch (CommandException e) {
             System.err.println(e.getMessage());
             if (verboseLevel > 0 && e.getCause() != null) {
         } 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) {
             }
             status = getStatusForError(e);
         } catch (Throwable e) {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
             status = 2;
         }
         System.exit(status);
             status = 2;
         }
         System.exit(status);
@@ -82,6 +85,7 @@ public class Main {
                 .defaultHelp(false);
         parser.addArgument("-v", "--verbose").action(Arguments.count());
         parser.addArgument("--log-file").type(File.class);
                 .defaultHelp(false);
         parser.addArgument("-v", "--verbose").action(Arguments.count());
         parser.addArgument("--log-file").type(File.class);
+        parser.addArgument("--scrub-log").action(Arguments.storeTrue());
 
         try {
             return parser.parseKnownArgs(args, null);
 
         try {
             return parser.parseKnownArgs(args, null);
@@ -90,9 +94,10 @@ public class Main {
         }
     }
 
         }
     }
 
-    private static void configureLogging(final int verboseLevel, final File logFile) {
+    private static void configureLogging(final int verboseLevel, final File logFile, final boolean scrubLog) {
         LogConfigurator.setVerboseLevel(verboseLevel);
         LogConfigurator.setLogFile(logFile);
         LogConfigurator.setVerboseLevel(verboseLevel);
         LogConfigurator.setLogFile(logFile);
+        LogConfigurator.setScrubSensitiveInformation(scrubLog);
 
         if (verboseLevel > 0) {
             java.util.logging.Logger.getLogger("")
 
         if (verboseLevel > 0) {
             java.util.logging.Logger.getLogger("")
@@ -104,16 +109,13 @@ public class Main {
     }
 
     private static int getStatusForError(final CommandException e) {
     }
 
     private static int getStatusForError(final CommandException e) {
-        if (e instanceof UserErrorException) {
-            return 1;
-        } else if (e instanceof UnexpectedErrorException) {
-            return 2;
-        } else if (e instanceof IOErrorException) {
-            return 3;
-        } else if (e instanceof UntrustedKeyErrorException) {
-            return 4;
-        } else {
-            return 2;
-        }
+        return switch (e) {
+            case UserErrorException userErrorException -> 1;
+            case UnexpectedErrorException unexpectedErrorException -> 2;
+            case IOErrorException ioErrorException -> 3;
+            case UntrustedKeyErrorException untrustedKeyErrorException -> 4;
+            case RateLimitErrorException rateLimitErrorException -> 5;
+            case null -> 2;
+        };
     }
 }
     }
 }