Skip to content

Commit e9cae3d

Browse files
committed
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 <amulhern@redhat.com>
1 parent 7c057ca commit e9cae3d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/stratis_cli/_error_reporting.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,15 @@ 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

9493
def _interpret_errors_0(error):

0 commit comments

Comments
 (0)