From c9b77fadad07beb2e2dd786f8cc38f9e32e0a352 Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 5 Sep 2025 10:09:25 -0400 Subject: [PATCH 1/2] Add an additional check for ServiceUnknown DBus error Signed-off-by: mulhern --- src/stratis_cli/_error_reporting.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/stratis_cli/_error_reporting.py b/src/stratis_cli/_error_reporting.py index 1fdd06d7a..9bafcf54c 100644 --- a/src/stratis_cli/_error_reporting.py +++ b/src/stratis_cli/_error_reporting.py @@ -91,7 +91,9 @@ def get_errors(exc: Exception): return -def _interpret_errors_0(error): +def _interpret_errors_0( + error: dbus.exceptions.DBusException, +): """ Handle match on SCAE .* DBE where: @@ -121,7 +123,10 @@ def _interpret_errors_0(error): # running with a new major version and is supplying a different name on the # D-Bus than stratis is attempting to use. The second and third # possibilities are both covered by a single error message. - if error.get_dbus_name() == "org.freedesktop.DBus.Error.NameHasNoOwner": + if error.get_dbus_name() in ( + "org.freedesktop.DBus.Error.NameHasNoOwner", + "org.freedesktop.DBus.Error.ServiceUnknown", + ): try: # pylint: disable=import-outside-toplevel # isort: THIRDPARTY From 1589d1a06a2bdd4e5748ce19f32a6fb094ab579b Mon Sep 17 00:00:00 2001 From: mulhern Date: Thu, 4 Sep 2025 22:10:05 -0400 Subject: [PATCH 2/2] Fix get_errors method There was a lot wrong with it, even though it has never, to my knowledge, failed. It used getattr incorrectly, without providing a default value of false, so that if the attribute was not present on the object, an AttributeError would be raised regardless. It would fall back on the context ancestor if there wasn't a cause, although I suspect it never did. This also was wrong, because the context would not give any help in determining the error message. Neither of these code defects is ever known to have caused a bug, but the ruff linter run by CodeRabbit objected to the construction, and it was correct. Signed-off-by: mulhern --- src/stratis_cli/_error_reporting.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/stratis_cli/_error_reporting.py b/src/stratis_cli/_error_reporting.py index 9bafcf54c..c0b25364f 100644 --- a/src/stratis_cli/_error_reporting.py +++ b/src/stratis_cli/_error_reporting.py @@ -79,16 +79,15 @@ def _interface_name_to_common_name(interface_name): raise StratisCliUnknownInterfaceError(interface_name) # pragma: no cover -def get_errors(exc: Exception): +def get_errors(exc: BaseException): """ Generates a sequence of exceptions starting with exc and following the chain of causes. """ - while True: - yield exc - exc = getattr(exc, "__cause__") or getattr(exc, "__context__") - if exc is None: - return + yield exc + while exc.__cause__ is not None: + yield exc.__cause__ + exc = exc.__cause__ def _interpret_errors_0(