python/qmp.py: add QMPProtocolError

In the case that we receive a reply but are unable to understand it,
use this exception name to indicate that case.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200710052220.3306-7-jsnow@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
This commit is contained in:
John Snow 2020-07-10 01:22:10 -04:00 committed by Philippe Mathieu-Daudé
parent 2e2d930517
commit 84dcdf0887

View File

@ -62,6 +62,12 @@ class QMPTimeoutError(QMPError):
""" """
class QMPProtocolError(QMPError):
"""
QMP protocol error; unexpected response
"""
class QMPResponseError(QMPError): class QMPResponseError(QMPError):
""" """
Represents erroneous QMP monitor reply Represents erroneous QMP monitor reply
@ -266,6 +272,10 @@ class QEMUMonitorProtocol:
ret = self.cmd(cmd, kwds) ret = self.cmd(cmd, kwds)
if 'error' in ret: if 'error' in ret:
raise QMPResponseError(ret) raise QMPResponseError(ret)
if 'return' not in ret:
raise QMPProtocolError(
"'return' key not found in QMP response '{}'".format(str(ret))
)
return cast(QMPReturnValue, ret['return']) return cast(QMPReturnValue, ret['return'])
def pull_event(self, wait=False): def pull_event(self, wait=False):