summaryrefslogtreecommitdiff
path: root/qface
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2022-01-27 10:42:52 +0100
committerDominik Holland <dominik.holland@googlemail.com>2022-01-27 12:33:11 +0100
commit4a5416e66b9bc1c9516d7bfccefda045d7ac487d (patch)
treec562a691fdb48b37b7161b4c0a407e8a4c9669fb /qface
parent8b91304fd1a5324aafa5c137fd40dfca1f9836ef (diff)
downloadqtivi-qface-4a5416e66b9bc1c9516d7bfccefda045d7ac487d.tar.gz
Improve error handling when parsing annotation files
The System.lookup() function is now throwing an exception when the name couldn't be found, instead of just returning None. This exception is catched in the FileSystem object and printed on stderr. In strict mode, any annotation error results in exiting the generator. Fixes: #90
Diffstat (limited to 'qface')
-rw-r--r--qface/generator.py17
-rw-r--r--qface/idl/domain.py6
2 files changed, 16 insertions, 7 deletions
diff --git a/qface/generator.py b/qface/generator.py
index d84a04c..297c2ef 100644
--- a/qface/generator.py
+++ b/qface/generator.py
@@ -345,10 +345,15 @@ class FileSystem(object):
return
meta = FileSystem.load_yaml(document)
click.secho('merge: {0}'.format(document.name), fg='blue')
- for identifier, data in meta.items():
- symbol = system.lookup(identifier)
- if symbol:
- merge(symbol.tags, data)
+ try:
+ for identifier, data in meta.items():
+ symbol = system.lookup(identifier)
+ if symbol:
+ merge(symbol.tags, data)
+ except Exception as e:
+ click.secho('Error parsing annotation {0}: {1}'.format(document, e), fg='red', err=True)
+ if FileSystem.strict:
+ sys.exit(-1)
@staticmethod
def parse(input, identifier: str = None, use_cache=False, clear_cache=True, pattern="*.qface", profile=EProfile.FULL):
@@ -391,6 +396,8 @@ class FileSystem(object):
if not document.exists():
if required:
click.secho('yaml document does not exists: {0}'.format(document), fg='red', err=True)
+ if FileSystem.strict:
+ sys.exit(-1)
return {}
try:
return yaml.load(document.text(), Loader=Loader)
@@ -399,4 +406,6 @@ class FileSystem(object):
if hasattr(exc, 'problem_mark'):
error = '{0}:{1}'.format(error, exc.problem_mark.line+1)
click.secho('{0}: error: {1}'.format(error, str(exc)), fg='red', err=True)
+ if FileSystem.strict:
+ sys.exit(-1)
return {}
diff --git a/qface/idl/domain.py b/qface/idl/domain.py
index 7949e6c..fbd0175 100644
--- a/qface/idl/domain.py
+++ b/qface/idl/domain.py
@@ -55,10 +55,10 @@ class System(object):
return self._moduleMap[name]
# <module>.<Symbol>
(module_name, type_name, fragment_name) = self.split_typename(name)
- if not module_name and type_name:
- click.secho('not able to lookup symbol: {0}'.format(name), fg='red')
- return None
+ if not module_name in self._moduleMap:
+ raise Exception('not able to lookup symbol: {0}'.format(name))
module = self._moduleMap[module_name]
+ # The module lookup calls this function again if the type_name doesn't exist
return module.lookup(type_name, fragment_name)
@staticmethod