diff mbox series

[06/26] qapi/parser.py: raise QAPIParseError during file opening

Message ID 20200922223525.4085762-7-jsnow@redhat.com
State New
Headers show
Series qapi: static typing conversion, pt5 | expand

Commit Message

John Snow Sept. 22, 2020, 10:35 p.m. UTC
Now that we can have exception contexts that don't specify a specific
line, we can use that context to raise errors when opening the file.

If we don't have a parent context, we can simply use our own.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/parser.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index fc0b1516cc..5a7233bc76 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -67,11 +67,13 @@  def __init__(self, fname, previously_included=None, incl_info=None):
             with open(self._fname, 'r', encoding='utf-8') as fp:
                 self.src = fp.read()
         except IOError as e:
-            raise QAPISemError(incl_info or QAPISourceInfo(None),
-                               "can't read %s file '%s': %s"
-                               % ("include" if incl_info else "schema",
-                                  self._fname,
-                                  e.strerror))
+            msg = "can't read {kind:s} file '{fname:s}': {errmsg:s}".format(
+                kind='include' if incl_info else 'schema',
+                fname=self._fname,
+                errmsg=e.strerror
+            )
+            context = incl_info or self.info
+            raise QAPIParseError(context, msg) from e
         self._parse()
 
     def _parse(self):