aboutsummaryrefslogtreecommitdiff
path: root/python/qemu/qmp/protocol.py
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2022-07-22 14:23:37 -0400
committerJohn Snow <jsnow@redhat.com>2025-09-15 14:36:01 -0400
commit2d26741fc5170e51621eb365a34460fadb5f969e (patch)
tree6ea43db8c8b4a5b400eb90fdc616b567b063edc7 /python/qemu/qmp/protocol.py
parent190d5d7fd725ff754f94e8e0cbfb69f279c82b5d (diff)
downloadqemu-2d26741fc5170e51621eb365a34460fadb5f969e.zip
qemu-2d26741fc5170e51621eb365a34460fadb5f969e.tar.gz
qemu-2d26741fc5170e51621eb365a34460fadb5f969e.tar.bz2
python: backport 'Change error classes to have better repr methods'
By passing all of the arguments to the base class and overriding the __str__ method when we want a different "human readable" message that isn't just printing the list of arguments, we can ensure that all custom error classes have a reasonable __repr__ implementation. In the case of ExecuteError, the pseudo-field that isn't actually correlated to an input argument can be re-imagined as a read-only property; this forces consistency in the class and makes the repr output more obviously correct. Signed-off-by: John Snow <jsnow@redhat.com> cherry picked from commit python-qemu-qmp@afdb7893f3b34212da4259b7202973f9a8cb85b3 Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'python/qemu/qmp/protocol.py')
-rw-r--r--python/qemu/qmp/protocol.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/python/qemu/qmp/protocol.py b/python/qemu/qmp/protocol.py
index a4ffdfa..86e5888 100644
--- a/python/qemu/qmp/protocol.py
+++ b/python/qemu/qmp/protocol.py
@@ -80,7 +80,7 @@ class ConnectError(QMPError):
:param exc: The root-cause exception.
"""
def __init__(self, error_message: str, exc: Exception):
- super().__init__(error_message)
+ super().__init__(error_message, exc)
#: Human-readable error string
self.error_message: str = error_message
#: Wrapped root cause exception
@@ -108,11 +108,14 @@ class StateError(QMPError):
"""
def __init__(self, error_message: str,
state: Runstate, required: Runstate):
- super().__init__(error_message)
+ super().__init__(error_message, state, required)
self.error_message = error_message
self.state = state
self.required = required
+ def __str__(self) -> str:
+ return self.error_message
+
F = TypeVar('F', bound=Callable[..., Any]) # pylint: disable=invalid-name