chiark / gitweb /
peerdb/tripe-newpeers.in: Mark expected errors and report appropriately.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 27 May 2018 15:43:16 +0000 (16:43 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 14 Jun 2018 11:50:38 +0000 (12:50 +0100)
Introduce an `ExpectedError' class and catch it at top level, reporting
the error message in the traditional Unix style.

peerdb/tripe-newpeers.in

index 0ba9cb61401ff298a37681d0fe5262c2ae07adaa..31d1e9f021363b507b33973a8813fd5ca4e96da3 100644 (file)
@@ -48,10 +48,12 @@ class CDBFake (object):
   def finish(me):
     pass
 
+class ExpectedError (Exception): pass
+
 ###--------------------------------------------------------------------------
 ### A bulk DNS resolver.
 
-class ResolverFailure (Exception):
+class ResolverFailure (ExpectedError):
   def __init__(me, host, msg):
     me.host = host
     me.msg = msg
@@ -134,7 +136,7 @@ RX_REF = RX.compile(r'(?x) \$ \( ([^)]+) \)')
 ## Match a $[HOST] name resolution reference; group 1 is the HOST.
 RX_RESOLVE = RX.compile(r'(?x) \$ \[ ([^]]+) \]')
 
-class ConfigSyntaxError (Exception):
+class ConfigSyntaxError (ExpectedError):
   def __init__(me, fname, lno, msg):
     me.fname = fname
     me.lno = lno
@@ -145,7 +147,7 @@ class ConfigSyntaxError (Exception):
 def _fmt_path(path):
   return ' -> '.join(["`%s'" % hop for hop in path])
 
-class AmbiguousOptionError (Exception):
+class AmbiguousOptionError (ExpectedError):
   def __init__(me, key, patha, vala, pathb, valb):
     me.key = key
     me.patha, me.vala = patha, vala
@@ -155,7 +157,7 @@ class AmbiguousOptionError (Exception):
         "path %s yields `%s' but %s yields `%s'" % \
         (me.key, _fmt_path(me.patha), me.vala, _fmt_path(me.pathb), me.valb)
 
-class InheritanceCycleError (Exception):
+class InheritanceCycleError (ExpectedError):
   def __init__(me, key, path):
     me.key = key
     me.path = path
@@ -163,13 +165,13 @@ class InheritanceCycleError (Exception):
     return "Found a cycle %s looking up key `%s'" % \
         (_fmt_path(me.path), me.key)
 
-class MissingSectionException (Exception):
+class MissingSectionException (ExpectedError):
   def __init__(me, sec):
     me.key = key
   def __str__(me):
     return "Section `%s' not found" % (me.sec)
 
-class MissingKeyException (Exception):
+class MissingKeyException (ExpectedError):
   def __init__(me, sec, key):
     me.sec = sec
     me.key = key
@@ -562,8 +564,12 @@ def main():
     cdb = CDB.cdbmake(opts.cdbfile, opts.cdbfile + '.new')
   else:
     cdb = CDBFake()
-  conf = getconf(args[1:])
-  output(conf, cdb)
+  try:
+    conf = getconf(args[1:])
+    output(conf, cdb)
+  except ExpectedError, e:
+    M.moan(str(e))
+    exit(2)
 
 if __name__ == '__main__':
   main()