mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-29 13:23:54 -06:00
qemu.py: Use custom exceptions rather than Exception
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 <ldoktor@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <20170818142613.32394-6-ldoktor@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
41f714b190
commit
a004e249f0
1 changed files with 15 additions and 2 deletions
|
@ -19,6 +19,19 @@ import subprocess
|
||||||
import qmp.qmp
|
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):
|
class QEMUMachine(object):
|
||||||
'''A QEMU VM
|
'''A QEMU VM
|
||||||
|
|
||||||
|
@ -213,9 +226,9 @@ class QEMUMachine(object):
|
||||||
'''
|
'''
|
||||||
reply = self.qmp(cmd, conv_keys, **args)
|
reply = self.qmp(cmd, conv_keys, **args)
|
||||||
if reply is None:
|
if reply is None:
|
||||||
raise Exception("Monitor is closed")
|
raise qmp.qmp.QMPError("Monitor is closed")
|
||||||
if "error" in reply:
|
if "error" in reply:
|
||||||
raise Exception(reply["error"]["desc"])
|
raise MonitorResponseError(reply)
|
||||||
return reply["return"]
|
return reply["return"]
|
||||||
|
|
||||||
def get_qmp_event(self, wait=False):
|
def get_qmp_event(self, wait=False):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue