From: John Snow Date: Thu, 11 Nov 2021 14:37:16 +0000 (-0500) Subject: python/aqmp: fix ConnectError string method X-Git-Tag: v6.2.0-rc2~21^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25de7f50121f251c45d111582d786db7ce0768d3;p=thirdparty%2Fqemu.git python/aqmp: fix ConnectError string method 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 Reported-by: Thomas Huth Tested-by: Thomas Huth Message-id: 20211111143719.2162525-3-jsnow@redhat.com Signed-off-by: John Snow --- diff --git a/python/qemu/aqmp/protocol.py b/python/qemu/aqmp/protocol.py index 860b79512d7..5190b33b13d 100644 --- a/python/qemu/aqmp/protocol.py +++ b/python/qemu/aqmp/protocol.py @@ -79,7 +79,11 @@ class ConnectError(AQMPError): 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):