[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 05/10] qemu.py: Use custom exceptions rather than
From: |
Lukáš Doktor |
Subject: |
[Qemu-devel] [PATCH v4 05/10] qemu.py: Use custom exceptions rather than Exception |
Date: |
Wed, 26 Jul 2017 16:42:21 +0200 |
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>
---
scripts/qemu.py | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index 5948e19..2bd522f 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'''
@@ -197,9 +210,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.9.4
- [Qemu-devel] [PATCH v4 00/10] qemu.py: Pylint/style fixes, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 01/10] qemu.py: Pylint/style fixes, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 02/10] qemu|qtest: Avoid dangerous arguments, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 03/10] qemu.py: Use iteritems rather than keys(), Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 04/10] qemu.py: Simplify QMP key-conversion, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 05/10] qemu.py: Use custom exceptions rather than Exception,
Lukáš Doktor <=
- [Qemu-devel] [PATCH v4 06/10] qmp.py: Couple of pylint/style fixes, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 07/10] qmp.py: Use object-based class for QEMUMonitorProtocol, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 08/10] qmp.py: Avoid "has_key" usage, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 09/10] qmp.py: Avoid overriding a builtin object, Lukáš Doktor, 2017/07/26
- [Qemu-devel] [PATCH v4 10/10] qtest.py: Few pylint/style fixes, Lukáš Doktor, 2017/07/26