[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 2/5] python/aqmp: fix ConnectError string method
From: |
John Snow |
Subject: |
[PULL 2/5] python/aqmp: fix ConnectError string method |
Date: |
Tue, 16 Nov 2021 19:33:14 -0500 |
When ConnectError is used to wrap an Exception that was initialized
without an error message, we are treated to a traceback with a rubbish
line like this:
... ConnectError: Failed to establish session:
Correct this to use the name of an exception as a fallback message:
... ConnectError: Failed to establish session: EOFError
Better!
Signed-off-by: John Snow <jsnow@redhat.com>
Reported-by: Thomas Huth <thuth@redhat.com>
Tested-by: Thomas Huth <thuth@redhat.com>
Message-id: 20211111143719.2162525-3-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/aqmp/protocol.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/python/qemu/aqmp/protocol.py b/python/qemu/aqmp/protocol.py
index 860b79512d..5190b33b13 100644
--- a/python/qemu/aqmp/protocol.py
+++ b/python/qemu/aqmp/protocol.py
@@ -79,7 +79,11 @@ def __init__(self, error_message: str, exc: Exception):
self.exc: Exception = exc
def __str__(self) -> str:
- return f"{self.error_message}: {self.exc!s}"
+ cause = str(self.exc)
+ if not cause:
+ # If there's no error string, use the exception name.
+ cause = exception_summary(self.exc)
+ return f"{self.error_message}: {cause}"
class StateError(AQMPError):
--
2.31.1
- [PULL 0/5] Python patches, John Snow, 2021/11/16
- [PULL 1/5] python/aqmp: Fix disconnect during capabilities negotiation, John Snow, 2021/11/16
- [PULL 2/5] python/aqmp: fix ConnectError string method,
John Snow <=
- [PULL 3/5] scripts/device-crash-test: simplify Exception handling, John Snow, 2021/11/16
- [PULL 4/5] scripts/device-crash-test: don't emit AQMP connection errors to stdout, John Snow, 2021/11/16
- [PULL 5/5] scripts/device-crash-test: hide tracebacks for QMP connect errors, John Snow, 2021/11/16
- Re: [PULL 0/5] Python patches, Richard Henderson, 2021/11/17
- Re: [PULL 0/5] Python patches, Gerd Hoffmann, 2021/11/17
- Re: [PULL 0/5] Python patches, Gerd Hoffmann, 2021/11/18