mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-30 22:03:54 -06:00
qapi: Prefix frontend errors with an "in definition" line
We take pains to include the offending expression in error messages, e.g. tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any' But not always: tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a list of strings Instead of improving them one by one, report the offending expression whenever it is known, like this: tests/qapi-schema/enum-if-invalid.json: In enum 'TestIfEnum': tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a list of strings Error messages that mention the offending expression become a bit redundant, e.g. tests/qapi-schema/alternate-any.json: In alternate 'Alt': tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any' I'll take care of that later in this series. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20190927134639.4284-5-armbru@redhat.com>
This commit is contained in:
parent
19e950d9d4
commit
7be6c51194
97 changed files with 110 additions and 1 deletions
|
@ -64,6 +64,12 @@ class QAPISourceInfo(object):
|
|||
self.fname = fname
|
||||
self.line = line
|
||||
self.parent = parent
|
||||
self.defn_meta = None
|
||||
self.defn_name = None
|
||||
|
||||
def set_defn(self, meta, name):
|
||||
self.defn_meta = meta
|
||||
self.defn_name = name
|
||||
|
||||
def next_line(self):
|
||||
info = copy.copy(self)
|
||||
|
@ -73,6 +79,12 @@ class QAPISourceInfo(object):
|
|||
def loc(self):
|
||||
return '%s:%d' % (self.fname, self.line)
|
||||
|
||||
def in_defn(self):
|
||||
if self.defn_name:
|
||||
return "%s: In %s '%s':\n" % (self.fname,
|
||||
self.defn_meta, self.defn_name)
|
||||
return ''
|
||||
|
||||
def include_path(self):
|
||||
ret = ''
|
||||
parent = self.parent
|
||||
|
@ -82,7 +94,7 @@ class QAPISourceInfo(object):
|
|||
return ret
|
||||
|
||||
def __str__(self):
|
||||
return self.include_path() + self.loc()
|
||||
return self.include_path() + self.in_defn() + self.loc()
|
||||
|
||||
|
||||
class QAPIError(Exception):
|
||||
|
@ -1127,6 +1139,7 @@ def check_exprs(exprs):
|
|||
normalize_if(expr)
|
||||
name = expr[meta]
|
||||
add_name(name, info, meta)
|
||||
info.set_defn(meta, name)
|
||||
if doc and doc.symbol != name:
|
||||
raise QAPISemError(info, "Definition of '%s' follows documentation"
|
||||
" for '%s'" % (name, doc.symbol))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue