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): ...@@ -47,7 +47,7 @@ class AugeasWrapper(object):
""" """
def __init__(self, confpath, lens, root=None, loadpath=None, 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. """Parse configuration file using given lens.
Params: Params:
...@@ -139,6 +139,7 @@ class AugeasNode(collections.MutableMapping): ...@@ -139,6 +139,7 @@ class AugeasNode(collections.MutableMapping):
assert path.startswith('/') assert path.startswith('/')
self._aug = aug self._aug = aug
self._path = path self._path = path
self._span = None
@property @property
def path(self): def path(self):
...@@ -154,6 +155,12 @@ class AugeasNode(collections.MutableMapping): ...@@ -154,6 +155,12 @@ class AugeasNode(collections.MutableMapping):
log.debug('tree get: %s = %s', self._path, value) log.debug('tree get: %s = %s', self._path, value)
return 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 @value.setter
def value(self, value): def value(self, value):
""" """
......
...@@ -177,7 +177,7 @@ class Entry: ...@@ -177,7 +177,7 @@ class Entry:
def __init__(self, node): def __init__(self, node):
""" Initialize data entry. """ """ Initialize data entry. """
self.node = node
self.origin = '.' self.origin = '.'
self.message = dns.message.Message() self.message = dns.message.Message()
self.message.use_edns(edns=0, payload=4096) self.message.use_edns(edns=0, payload=4096)
...@@ -194,6 +194,7 @@ class Entry: ...@@ -194,6 +194,7 @@ class Entry:
# MATCH # MATCH
self.match_fields = [m.value for m in node.match("/match")] self.match_fields = [m.value for m in node.match("/match")]
if not self.match_fields: if not self.match_fields:
self.match_fields = ['opcode', 'qtype', 'qname'] self.match_fields = ['opcode', 'qtype', 'qname']
...@@ -219,10 +220,9 @@ class Entry: ...@@ -219,10 +220,9 @@ class Entry:
# MANDATORY # MANDATORY
try: try:
_ = list(node.match("/mandatory"))[0].value self.mandatory = list(node.match("/mandatory"))[0]
self.mandatory = True
except (KeyError, IndexError): except (KeyError, IndexError):
self.mandatory = False self.mandatory = None
# TSIG # TSIG
try: try:
...@@ -372,7 +372,8 @@ class Entry: ...@@ -372,7 +372,8 @@ class Entry:
self.match_part(code, msg) self.match_part(code, msg)
except ValueError as ex: except ValueError as ex:
errstr = '%s in the response:\n%s' % (str(ex), msg.to_text()) 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): def cmp_raw(self, raw_value):
assert self.is_raw_data_entry assert self.is_raw_data_entry
...@@ -447,6 +448,7 @@ class Range: ...@@ -447,6 +448,7 @@ class Range:
def __init__(self, node): def __init__(self, node):
""" Initialize reply range. """ """ Initialize reply range. """
self.node = node
self.a = int(node['/from'].value) self.a = int(node['/from'].value)
self.b = int(node['/to'].value) self.b = int(node['/to'].value)
...@@ -522,6 +524,7 @@ class Step: ...@@ -522,6 +524,7 @@ class Step:
def __init__(self, node): def __init__(self, node):
""" Initialize single scenario step. """ """ Initialize single scenario step. """
self.node = node
self.id = int(node.value) self.id = int(node.value)
self.type = node["/type"].value self.type = node["/type"].value
self.log = StepLogger(logging.getLogger('pydnstest.scenario.Step'), self.log = StepLogger(logging.getLogger('pydnstest.scenario.Step'),
...@@ -736,6 +739,7 @@ class Scenario: ...@@ -736,6 +739,7 @@ class Scenario:
def __init__(self, node, filename): def __init__(self, node, filename):
""" Initialize scenario with description. """ """ Initialize scenario with description. """
self.node = node
self.info = node.value self.info = node.value
self.file = filename self.file = filename
self.ranges = [Range(n) for n in node.match("/range")] self.ranges = [Range(n) for n in node.match("/range")]
...@@ -833,9 +837,9 @@ class Scenario: ...@@ -833,9 +837,9 @@ class Scenario:
for r in self.ranges: for r in self.ranges:
for e in r.stored: for e in r.stored:
if e.mandatory is True and e.fired == 0: if e.mandatory and e.fired == 0:
# TODO: cisla radku # 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): 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