chiark / gitweb /
better config errors
[hippotat.git] / hippotat / __init__.py
index 6b87da9f63919f64979e3bf8680bc361a99abdc3..d0cc79902753286e2afa0c254297094e5c73de8d 100644 (file)
@@ -20,6 +20,7 @@ import ipaddress
 from ipaddress import AddressValueError
 
 from optparse import OptionParser
+import configparser
 from configparser import ConfigParser
 from configparser import NoOptionError
 
@@ -403,7 +404,7 @@ def process_cfg_clients(constructor):
 
 #---------- startup ----------
 
-def common_startup():
+def common_startup(process_cfg):
   re = regexp.compile('#.*')
   cfg.read_string(re.sub('', defcfg))
   need_defcfg = True
@@ -514,6 +515,12 @@ just `+': all DFLAGs.
     readconfig('/etc/hippotat/config',   False)
     readconfig('/etc/hippotat/config.d', False)
 
+  try: process_cfg()
+  except (configparser.Error, ValueError):
+    traceback.print_exc(file=sys.stderr)
+    print('\nInvalid configuration, giving up.', file=sys.stderr)
+    sys.exit(12)
+
   #print(repr(debug_set), file=sys.stderr)
 
   log_formatter = twisted.logger.formatEventAsClassicLogText