[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [collector/master] Avoid confusing new users; just print usage instead of a stack trace for miss-configuration.



commit dedb8226f279bb2d889d00858290fdf72eaa2b50
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Tue Aug 23 17:29:43 2016 +0200

    Avoid confusing new users; just print usage instead of a stack trace for miss-configuration.
---
 src/main/java/org/torproject/collector/Main.java | 34 ++++++++++++++----------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/torproject/collector/Main.java b/src/main/java/org/torproject/collector/Main.java
index 96097b3..997ee2a 100644
--- a/src/main/java/org/torproject/collector/Main.java
+++ b/src/main/java/org/torproject/collector/Main.java
@@ -5,6 +5,7 @@ package org.torproject.collector;
 
 import org.torproject.collector.bridgedescs.SanitizedBridgesWriter;
 import org.torproject.collector.conf.Configuration;
+import org.torproject.collector.conf.ConfigurationException;
 import org.torproject.collector.conf.Key;
 import org.torproject.collector.cron.CollecTorMain;
 import org.torproject.collector.cron.Scheduler;
@@ -57,22 +58,27 @@ public class Main {
    * See class description {@link Main}.
    */
   public static void main(String[] args) throws Exception {
-    Path confPath = null;
-    if (args == null || args.length == 0) {
-      confPath = Paths.get(CONF_FILE);
-    } else if (args.length == 1) {
-      confPath = Paths.get(args[0]);
-    } else {
-      printUsage("CollecTor takes at most one argument.");
-      return;
-    }
-    if (!confPath.toFile().exists() || confPath.toFile().length() < 1L) {
-      writeDefaultConfig(confPath);
+    try {
+      Path confPath = null;
+      if (args == null || args.length == 0) {
+        confPath = Paths.get(CONF_FILE);
+      } else if (args.length == 1) {
+        confPath = Paths.get(args[0]);
+      } else {
+        printUsage("CollecTor takes at most one argument.");
+        return;
+      }
+      if (!confPath.toFile().exists() || confPath.toFile().length() < 1L) {
+        writeDefaultConfig(confPath);
+        return;
+      } else {
+        conf.setWatchableSourceAndLoad(confPath);
+      }
+      Scheduler.getInstance().scheduleModuleRuns(collecTorMains, conf);
+    } catch (ConfigurationException ce) {
+      printUsage(ce.getMessage());
       return;
-    } else {
-      conf.setWatchableSourceAndLoad(confPath);
     }
-    Scheduler.getInstance().scheduleModuleRuns(collecTorMains, conf);
   }
 
   private static void printUsage(String msg) {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits