aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2017-12-10 05:15:41 +0100
committerKlement Sekera <ksekera@cisco.com>2017-12-10 05:17:07 +0100
commit32a9d7bf63015aeeb6dee4a2342933be58871176 (patch)
tree6bee4755dc047be3993807295a29a0aaaaaa06a5
parent10593f81a7cfec2d0664f7c8abd173e1a33348cf (diff)
improve vapi json parser error handling
Change-Id: I39b975e6dc3b3ed1f81c1736ed498aee05f6a88b Signed-off-by: Klement Sekera <ksekera@cisco.com>
-rw-r--r--src/vpp-api/vapi/vapi_json_parser.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py
index 4e62720d37e..a9186a15334 100644
--- a/src/vpp-api/vapi/vapi_json_parser.py
+++ b/src/vpp-api/vapi/vapi_json_parser.py
@@ -50,6 +50,9 @@ class Type(object):
def __init__(self, name):
self.name = name
+ def __str__(self):
+ return self.name
+
class SimpleType (Type):
@@ -85,6 +88,9 @@ class Struct(object):
self.fields = fields
self.field_names = [n.name for n in self.fields]
+ def __str__(self):
+ return "[%s]" % "], [".join([str(f) for f in self.fields])
+
class Message(object):
@@ -123,7 +129,14 @@ class Message(object):
if field_type in typedict:
field_type = typedict[field_type]
else:
- field_type = typedict[remove_magic(field_type)]
+ mundane_field_type = remove_magic(field_type)
+ if mundane_field_type in typedict:
+ field_type = typedict[mundane_field_type]
+ else:
+ raise ParseError(
+ "While parsing message `%s': could not find "
+ "type by magic name `%s' nor by mundane name "
+ "`%s'" % (name, field_type, mundane_field_type))
if len(field) == 2:
if self.header is not None and\
self.header.has_field(field[1]):
@@ -200,6 +213,10 @@ class StructType (Type, Struct):
Type.__init__(self, name)
Struct.__init__(self, name, fields)
+ def __str__(self):
+ return "StructType(%s, %s)" % (Type.__str__(self),
+ Struct.__str__(self))
+
def has_field(self, name):
return name in self.field_names
@@ -262,6 +279,7 @@ class JsonParser(object):
continue
self.types[type_.name] = type_
self.types_by_json[path][type_.name] = type_
+ self.logger.debug("Parsed type: %s" % type_)
for m in j['messages']:
try:
msg = self.message_class(self.logger, m, self.types,