Skip to content

Commit 24d7fd2

Browse files
authored
Merge pull request #1213 from mulkieran/fix-get-errors-bug
Fix get_errors method
2 parents 7c057ca + 1589d1a commit 24d7fd2

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/stratis_cli/_error_reporting.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,20 @@ def _interface_name_to_common_name(interface_name):
7979
raise StratisCliUnknownInterfaceError(interface_name) # pragma: no cover
8080

8181

82-
def get_errors(exc: Exception):
82+
def get_errors(exc: BaseException):
8383
"""
8484
Generates a sequence of exceptions starting with exc and following the chain
8585
of causes.
8686
"""
87-
while True:
88-
yield exc
89-
exc = getattr(exc, "__cause__") or getattr(exc, "__context__")
90-
if exc is None:
91-
return
87+
yield exc
88+
while exc.__cause__ is not None:
89+
yield exc.__cause__
90+
exc = exc.__cause__
9291

9392

94-
def _interpret_errors_0(error):
93+
def _interpret_errors_0(
94+
error: dbus.exceptions.DBusException,
95+
):
9596
"""
9697
Handle match on SCAE .* DBE
9798
where:
@@ -121,7 +122,10 @@ def _interpret_errors_0(error):
121122
# running with a new major version and is supplying a different name on the
122123
# D-Bus than stratis is attempting to use. The second and third
123124
# possibilities are both covered by a single error message.
124-
if error.get_dbus_name() == "org.freedesktop.DBus.Error.NameHasNoOwner":
125+
if error.get_dbus_name() in (
126+
"org.freedesktop.DBus.Error.NameHasNoOwner",
127+
"org.freedesktop.DBus.Error.ServiceUnknown",
128+
):
125129
try:
126130
# pylint: disable=import-outside-toplevel
127131
# isort: THIRDPARTY

0 commit comments

Comments
 (0)