Commit 1fd28bb0 authored by Štěpán Balážik's avatar Štěpán Balážik

Re-added positional information to error messagess

parent 92b006ab
......@@ -47,7 +47,7 @@ class AugeasWrapper(object):
"""
def __init__(self, confpath, lens, root=None, loadpath=None,
flags=Augeas.NO_MODL_AUTOLOAD | Augeas.NO_LOAD):
flags=Augeas.NO_MODL_AUTOLOAD | Augeas.NO_LOAD | Augeas.ENABLE_SPAN):
"""Parse configuration file using given lens.
Params:
......@@ -139,6 +139,7 @@ class AugeasNode(collections.MutableMapping):
assert path.startswith('/')
self._aug = aug
self._path = path
self._span = None
@property
def path(self):
......@@ -154,6 +155,12 @@ class AugeasNode(collections.MutableMapping):
log.debug('tree get: %s = %s', self._path, value)
return value
@property
def span(self):
if self._span is None:
self._span = "char position %s" % self._aug.span(self._path)[5]
return self._span
@value.setter
def value(self, value):
"""
......
......@@ -177,7 +177,7 @@ class Entry:
def __init__(self, node):
""" Initialize data entry. """
self.node = node
self.origin = '.'
self.message = dns.message.Message()
self.message.use_edns(edns=0, payload=4096)
......@@ -194,6 +194,7 @@ class Entry:
# MATCH
self.match_fields = [m.value for m in node.match("/match")]
if not self.match_fields:
self.match_fields = ['opcode', 'qtype', 'qname']
......@@ -219,10 +220,9 @@ class Entry:
# MANDATORY
try:
_ = list(node.match("/mandatory"))[0].value
self.mandatory = True
self.mandatory = list(node.match("/mandatory"))[0]
except (KeyError, IndexError):
self.mandatory = False
self.mandatory = None
# TSIG
try:
......@@ -372,7 +372,8 @@ class Entry:
self.match_part(code, msg)
except ValueError as ex:
errstr = '%s in the response:\n%s' % (str(ex), msg.to_text())
raise ValueError("line %d, \"%s\": %s" % (42, code, errstr)) # TODO: cisla radku
# TODO: cisla radku
raise ValueError("%s, \"%s\": %s" % (self.node.span, code, errstr))
def cmp_raw(self, raw_value):
assert self.is_raw_data_entry
......@@ -447,6 +448,7 @@ class Range:
def __init__(self, node):
""" Initialize reply range. """
self.node = node
self.a = int(node['/from'].value)
self.b = int(node['/to'].value)
......@@ -522,6 +524,7 @@ class Step:
def __init__(self, node):
""" Initialize single scenario step. """
self.node = node
self.id = int(node.value)
self.type = node["/type"].value
self.log = StepLogger(logging.getLogger('pydnstest.scenario.Step'),
......@@ -736,6 +739,7 @@ class Scenario:
def __init__(self, node, filename):
""" Initialize scenario with description. """
self.node = node
self.info = node.value
self.file = filename
self.ranges = [Range(n) for n in node.match("/range")]
......@@ -833,9 +837,9 @@ class Scenario:
for r in self.ranges:
for e in r.stored:
if e.mandatory is True and e.fired == 0:
if e.mandatory and e.fired == 0:
# TODO: cisla radku
raise RuntimeError('Mandatory section at line %d is not fired' % 42)
raise RuntimeError('Mandatory section at %s not fired' % e.mandatory.span)
def get_next(file_in, skip_empty=True):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment