[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/15] qemu.py: Use custom exceptions rather than Exc
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL 05/15] qemu.py: Use custom exceptions rather than Exception |
Date: |
Fri, 15 Sep 2017 20:37:29 -0300 |
From: Lukáš Doktor <address@hidden>
The naked Exception should not be widely used. It makes sense to be a
bit more specific and use better-suited custom exceptions. As a benefit
we can store the full reply in the exception in case someone needs it
when catching the exception.
Signed-off-by: Lukáš Doktor <address@hidden>
Reviewed-by: Eduardo Habkost <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
scripts/qemu.py | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index bde8da8fe7..7c6802609a 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -19,6 +19,19 @@ import subprocess
import qmp.qmp
+class MonitorResponseError(qmp.qmp.QMPError):
+ '''
+ Represents erroneous QMP monitor reply
+ '''
+ def __init__(self, reply):
+ try:
+ desc = reply["error"]["desc"]
+ except KeyError:
+ desc = reply
+ super(MonitorResponseError, self).__init__(desc)
+ self.reply = reply
+
+
class QEMUMachine(object):
'''A QEMU VM
@@ -213,9 +226,9 @@ class QEMUMachine(object):
'''
reply = self.qmp(cmd, conv_keys, **args)
if reply is None:
- raise Exception("Monitor is closed")
+ raise qmp.qmp.QMPError("Monitor is closed")
if "error" in reply:
- raise Exception(reply["error"]["desc"])
+ raise MonitorResponseError(reply)
return reply["return"]
def get_qmp_event(self, wait=False):
--
2.13.5
- [Qemu-devel] [PULL 00/15] Python queue, 2017-09-15, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 01/15] qemu.py: Pylint/style fixes, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 02/15] qemu|qtest: Avoid dangerous arguments, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 03/15] qemu.py: Use iteritems rather than keys(), Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 04/15] qemu.py: Simplify QMP key-conversion, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 05/15] qemu.py: Use custom exceptions rather than Exception,
Eduardo Habkost <=
- [Qemu-devel] [PULL 07/15] qmp.py: Use object-based class for QEMUMonitorProtocol, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 06/15] qmp.py: Couple of pylint/style fixes, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 08/15] qmp.py: Avoid "has_key" usage, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 09/15] qmp.py: Avoid overriding a builtin object, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 10/15] qtest.py: Few pylint/style fixes, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 11/15] qemu.py: fix is_running() return before first launch(), Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 12/15] qemu.py: avoid writing to stdout/stderr, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 13/15] qemu.py: use os.path.null instead of /dev/null, Eduardo Habkost, 2017/09/15
- [Qemu-devel] [PULL 14/15] qemu.py: improve message on negative exit code, Eduardo Habkost, 2017/09/15