[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 06/16] python/qmp.py: add QMPProtocolError
From: |
John Snow |
Subject: |
[PATCH v2 06/16] python/qmp.py: add QMPProtocolError |
Date: |
Tue, 2 Jun 2020 17:45:18 -0400 |
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>
---
python/qemu/qmp.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py
index 5f3558e3066..1aefc00c93b 100644
--- a/python/qemu/qmp.py
+++ b/python/qemu/qmp.py
@@ -62,6 +62,12 @@ class QMPTimeoutError(QMPError):
"""
+class QMPProtocolError(QMPError):
+ """
+ QMP protocol error; unexpected response
+ """
+
+
class QMPResponseError(QMPError):
"""
Represents erroneous QMP monitor reply
@@ -266,6 +272,10 @@ def command(self, cmd, **kwds):
ret = self.cmd(cmd, kwds)
if 'error' in 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'])
def pull_event(self, wait=False):
--
2.21.3
- [PATCH v2 00/16] python: add mypy support to python/qemu, John Snow, 2020/06/02
- [PATCH v2 02/16] iotests.py: use qemu.qmp type aliases, John Snow, 2020/06/02
- [PATCH v2 01/16] python/qmp.py: Define common types, John Snow, 2020/06/02
- [PATCH v2 03/16] python/qmp.py: re-absorb MonitorResponseError, John Snow, 2020/06/02
- [PATCH v2 04/16] python/qmp.py: Do not return None from cmd_obj, John Snow, 2020/06/02
- [PATCH v2 05/16] python/qmp.py: add casts to JSON deserialization, John Snow, 2020/06/02
- [PATCH v2 06/16] python/qmp.py: add QMPProtocolError,
John Snow <=
- [PATCH v2 07/16] python/machine.py: Fix monitor address typing, John Snow, 2020/06/02
- [PATCH v2 09/16] python/machine.py: Don't modify state in _base_args(), John Snow, 2020/06/02
- [PATCH v2 08/16] python/machine.py: reorder __init__, John Snow, 2020/06/02
- [PATCH v2 10/16] python/machine.py: Handle None events in event_wait, John Snow, 2020/06/02
- [PATCH v2 12/16] python/machine.py: Add _qmp access shim, John Snow, 2020/06/02
- [PATCH v2 11/16] python/machine.py: use qmp.command, John Snow, 2020/06/02
- [PATCH v2 14/16] python/qemu: make 'args' style arguments immutable, John Snow, 2020/06/02
- [PATCH v2 13/16] python/machine.py: fix _popen access, John Snow, 2020/06/02