summary refs log tree commit diff stats
path: root/python/qemu/qmp/message.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/message.py
parent190d5d7fd725ff754f94e8e0cbfb69f279c82b5d (diff)
downloadfocaccia-qemu-2d26741fc5170e51621eb365a34460fadb5f969e.tar.gz
focaccia-qemu-2d26741fc5170e51621eb365a34460fadb5f969e.zip
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/message.py')
-rw-r--r--python/qemu/qmp/message.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/python/qemu/qmp/message.py b/python/qemu/qmp/message.py
index f76ccc9074..c2e9dd0dd5 100644
--- a/python/qemu/qmp/message.py
+++ b/python/qemu/qmp/message.py
@@ -178,15 +178,15 @@ class DeserializationError(ProtocolError):
     :param raw: The raw `bytes` that prompted the failure.
     """
     def __init__(self, error_message: str, raw: bytes):
-        super().__init__(error_message)
+        super().__init__(error_message, raw)
         #: The raw `bytes` that were not understood as JSON.
         self.raw: bytes = raw
 
     def __str__(self) -> str:
-        return "\n".join([
+        return "\n".join((
             super().__str__(),
             f"  raw bytes were: {str(self.raw)}",
-        ])
+        ))
 
 
 class UnexpectedTypeError(ProtocolError):
@@ -197,13 +197,13 @@ class UnexpectedTypeError(ProtocolError):
     :param value: The deserialized JSON value that wasn't an object.
     """
     def __init__(self, error_message: str, value: object):
-        super().__init__(error_message)
+        super().__init__(error_message, value)
         #: The JSON value that was expected to be an object.
         self.value: object = value
 
     def __str__(self) -> str:
         strval = json.dumps(self.value, indent=2)
-        return "\n".join([
+        return "\n".join((
             super().__str__(),
             f"  json value was: {strval}",
-        ])
+        ))