Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_causes():
e1, e2, e3 = AttributeError("foo"), KeyError("bar"), IndexError("baz")
try:
try:
# e3 will be e2's __cause__
raise e2 from e3
except Exception:
# e2 will be e1's __context__
raise e1
except Exception as exc2:
result = list(utils.causes(exc2))
assert result == [e1, e2, e3]
def handle_errors():
try:
yield
except Exception as exc:
logger.debug("Exception details:", exc_info=exc)
messages = [str(e) for e in utils.causes(exc)]
raise click.ClickException("\n".join(e for e in messages if e))