[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/26] qapi/parser.py: raise QAPIParseError during file opening
From: |
John Snow |
Subject: |
[PATCH 06/26] qapi/parser.py: raise QAPIParseError during file opening |
Date: |
Tue, 22 Sep 2020 18:35:05 -0400 |
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 --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):
--
2.26.2
- [PATCH 00/26] qapi: static typing conversion, pt5, John Snow, 2020/09/22
- [PATCH 03/26] qapi/parser.py: use 'with' statement for opening files, John Snow, 2020/09/22
- [PATCH 02/26] qapi/parser.py: group variable declarations in __init__, John Snow, 2020/09/22
- [PATCH 04/26] qapi/source.py: Add default arguments to QAPISourceInfo, John Snow, 2020/09/22
- [PATCH 01/26] qapi/parser.py: refactor parsing routine into method, John Snow, 2020/09/22
- [PATCH 05/26] qapi/parser.py: start source info at line 0, John Snow, 2020/09/22
- [PATCH 07/26] qapi/parser.py: fully remove 'null' constant, John Snow, 2020/09/22
- [PATCH 08/26] qapi/parser.py: Assert lexer value is a string, John Snow, 2020/09/22
- [PATCH 06/26] qapi/parser.py: raise QAPIParseError during file opening,
John Snow <=
- [PATCH 09/26] qapi/parser.py: assert get_expr returns object in outer loop, John Snow, 2020/09/22
- [PATCH 10/26] qapi/parser.py: assert object keys are strings, John Snow, 2020/09/22
- [PATCH 11/26] qapi/parser.py: Convert several methods to @classmethod, John Snow, 2020/09/22
- [PATCH 12/26] qapi/parser.py: add casts to pragma checks, John Snow, 2020/09/22
- [PATCH 13/26] qapi/parser.py: add type hint annotations, John Snow, 2020/09/22
- [PATCH 14/26] qapi/parser.py: add docstrings, John Snow, 2020/09/22
- [PATCH 15/26] qapi/parser.py: add ParsedExpression type, John Snow, 2020/09/22
- [PATCH 16/26] qapi/pragma.py: Move QAPISchemaPragma into its own module, John Snow, 2020/09/22
- [PATCH 18/26] qapi/parser.py: Modify _include() to use parser state, John Snow, 2020/09/22
- [PATCH 17/26] qapi/pragma.py: Move pragma parsing out of parser.py, John Snow, 2020/09/22