Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a __str__ to ActionFailed, for better unexpected failure output #1209

Merged
merged 3 commits into from
May 16, 2024

Conversation

tonyandrewmeyer
Copy link
Contributor

Add a __str__ to ops.testing.ActionFailed so that an uncaught event.fail() in tests produces a more informative traceback.

Currently, event.fail() and event.fail(message) will look somewhat like:

Traceback (most recent call last):
  File "/tmp/1204.py", line 18, in <module>
    harness.run_action("act")
  File "/home/tameyer/code/operator/ops/testing.py", line 2001, in run_action
    raise ActionFailed(
ops.testing.ActionFailed

After this PR, event.fail() will look like:

Traceback (most recent call last):
  File "/tmp/1204.py", line 19, in <module>
    harness.run_action("act")
  File "/home/tameyer/code/operator/ops/testing.py", line 2006, in run_action
    raise ActionFailed(
ops.testing.ActionFailed: Event handler called `fail()` with no additional details.

and event.fail("Message") will look like:

Traceback (most recent call last):
  File "/tmp/1204.py", line 18, in <module>
    harness.run_action("act")
  File "/home/tameyer/code/operator/ops/testing.py", line 2006, in run_action
    raise ActionFailed(
ops.testing.ActionFailed: Message

Fixes #1204

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tonyandrewmeyer tonyandrewmeyer merged commit f1ff257 into canonical:main May 16, 2024
26 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the actionfailed-str-1204 branch May 16, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve how ActionFailed appears in traceback
3 participants