Handle python standard exceptions in qubesd response

This may be useful for things like AttributeError, ValueError etc.
Use error name directly as exception name without much validation, as it
comes from dom0.
This commit is contained in:
Marek Marczykowski-Górecki 2017-03-09 01:33:31 +01:00
parent 6b8bbd9c51
commit bf03f6630f
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -78,7 +78,14 @@ class PropertyHolder(object):
args = [arg.decode() for arg in args.split(b'\x00')[:-1]]
format_string = format_string.decode('utf-8')
exc_type = exc_type.decode('ascii')
exc_class = getattr(qubesmgmt.exc, exc_type, 'QubesException')
try:
exc_class = getattr(qubesmgmt.exc, exc_type)
except AttributeError:
if exc_type.endswith('Error'):
exc_class = __builtins__.get(exc_type,
qubesmgmt.exc.QubesException)
else:
exc_class = qubesmgmt.exc.QubesException
# TODO: handle traceback if given
raise exc_class(format_string, *args)
else: