commit dedb8226f279bb2d889d00858290fdf72eaa2b50 Author: iwakeh iwakeh@torproject.org 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) {