chiark / gitweb /
peerdb/tripe-newpeers.in (MissingSectionException): Fix constructor.
[tripe] / peerdb / tripe-newpeers.in
index 1213b904aad2877afe380846c8c06dea4139554e..81e62f75fa8c2727f226a10c4e6ae563151b678d 100644 (file)
@@ -48,9 +48,18 @@ class CDBFake (object):
   def finish(me):
     pass
 
+class ExpectedError (Exception): pass
+
 ###--------------------------------------------------------------------------
 ### A bulk DNS resolver.
 
+class ResolverFailure (ExpectedError):
+  def __init__(me, host, msg):
+    me.host = host
+    me.msg = msg
+  def __str__(me):
+    return "failed to resolve `%s': %s" % (me.host, me.msg)
+
 class BulkResolver (object):
   """
   Resolve a number of DNS names in parallel.
@@ -92,7 +101,7 @@ class BulkResolver (object):
     """
     addr = me._namemap[host]
     if addr is None:
-      raise KeyError(host)
+      raise ResolverFailure(host, '(unknown failure)')
     return addr
 
   def _resolved(me, host, addr):
@@ -127,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
@@ -138,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
@@ -148,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
@@ -156,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
+    me.sec = sec
   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
@@ -313,7 +322,7 @@ class ConfigSection (object):
     """
 
     ## Initialize for a depth-first walk of the inheritance graph.
-    seen = {}
+    seen = { 'name': True }
     visiting = { me.name: True }
     stack = [me]
 
@@ -555,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()