From: Mark Wooding Date: Sun, 27 May 2018 15:43:16 +0000 (+0100) Subject: peerdb/tripe-newpeers.in: Mark expected errors and report appropriately. X-Git-Tag: 1.5.0~65 X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/commitdiff_plain/1c4623dde993c3ef57ff6f8f3e1608073325fa37?hp=6f48da4ac71b5944d0464dd940ced3baf0d4311b peerdb/tripe-newpeers.in: Mark expected errors and report appropriately. Introduce an `ExpectedError' class and catch it at top level, reporting the error message in the traditional Unix style. --- diff --git a/peerdb/tripe-newpeers.in b/peerdb/tripe-newpeers.in index 0ba9cb61..31d1e9f0 100644 --- a/peerdb/tripe-newpeers.in +++ b/peerdb/tripe-newpeers.in @@ -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()