Permalink
Browse files

Nicer error messages on invalid zone files

  • Loading branch information...
Barnaby Gray
Barnaby Gray committed Mar 13, 2013
1 parent fe76987 commit e048bfafcaa6a209ca81d30c667510dfd5c8344f
Showing with 20 additions and 5 deletions.
  1. +0 −1 abc
  2. +13 −4 scripts/cli53
  3. +2 −0 tests/invalid1.txt
  4. +5 −0 tests/test_bind.py
View
1 abc
@@ -1 +0,0 @@
-abc
View
@@ -58,6 +58,9 @@ except ImportError:
sys.exit(-1)
+class ParseException(Exception):
+ pass
+
# Custom base class to prevent changing values
class CustomBase(dns.rdtypes.nsbase.NSBase):
def to_text(self, **kw):
@@ -564,12 +567,15 @@ def cmd_import(args):
m = re_origin.search(text)
if not m:
- raise Exception('Could not find $ORIGIN')
+ raise ParseException('%s: Could not find $ORIGIN' % args.file.name)
origin = m.group(1)
if not origin.endswith('.'):
- raise Exception('$ORIGIN must end with a period (.)')
+ raise ParseException('%s: $ORIGIN must end with a period (.)' % args.file.name)
- zone = dns.zone.from_text(text, origin=origin, check_origin=False)
+ try:
+ zone = dns.zone.from_text(text, origin=origin, check_origin=False)
+ except dns.exception.SyntaxError as ex:
+ raise ParseException('%s: %s' % (args.file.name, ex))
old_zone = None
if args.replace:
@@ -818,7 +824,10 @@ def main():
parser_rrlist.set_defaults(func=cmd_rrlist)
args = parser.parse_args()
- args.func(args)
+ try:
+ args.func(args)
+ except ParseException as ex:
+ raise SystemExit("Parse error: %s" % ex)
if __name__=='__main__':
main()
View
@@ -0,0 +1,2 @@
+@ 900 IN SOA ns1.somenameserver.com. blah.example.com. 1 7200 900 1209600 86400
+XYZ
View
@@ -128,3 +128,8 @@ def test_aws_extensions(self):
],
output
)
+
+ def test_invalid1(self):
+ fname = self._zonefile('invalid1.txt')
+ self.assertRaises(NonZeroExit,
+ self._cmd, 'import', '--file', fname, self.zone)

0 comments on commit e048bfa

Please sign in to comment.