summary refs log tree commit diff stats
path: root/python/qemu/qmp.py
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2020-07-10 01:22:07 -0400
committerPhilippe Mathieu-Daudé <philmd@redhat.com>2020-07-14 22:22:22 +0200
commite3a23b4803a3939c7e24e8946880f5ef369ef781 (patch)
tree8bb2ed6d555453586ef513915dc210f132f2cd1a /python/qemu/qmp.py
parent2012453ddde0506d044d4739257227c6868028b6 (diff)
downloadfocaccia-qemu-e3a23b4803a3939c7e24e8946880f5ef369ef781.tar.gz
focaccia-qemu-e3a23b4803a3939c7e24e8946880f5ef369ef781.zip
python/qmp.py: re-absorb MonitorResponseError
When I initially split this out, I considered this more of a machine
error than a QMP protocol error, but I think that's misguided.

Move this back to qmp.py and name it QMPResponseError. Convert
qmp.command() to use this exception type.

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-4-jsnow@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'python/qemu/qmp.py')
-rw-r--r--python/qemu/qmp.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py
index 8388c7b603..aa8a666b8a 100644
--- a/python/qemu/qmp.py
+++ b/python/qemu/qmp.py
@@ -61,6 +61,19 @@ class QMPTimeoutError(QMPError):
     """
 
 
+class QMPResponseError(QMPError):
+    """
+    Represents erroneous QMP monitor reply
+    """
+    def __init__(self, reply: QMPMessage):
+        try:
+            desc = reply['error']['desc']
+        except KeyError:
+            desc = reply
+        super().__init__(desc)
+        self.reply = reply
+
+
 class QEMUMonitorProtocol:
     """
     Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
@@ -251,8 +264,8 @@ class QEMUMonitorProtocol:
         Build and send a QMP command to the monitor, report errors if any
         """
         ret = self.cmd(cmd, kwds)
-        if "error" in ret:
-            raise Exception(ret['error']['desc'])
+        if 'error' in ret:
+            raise QMPResponseError(ret)
         return ret['return']
 
     def pull_event(self, wait=False):