Skip to content

Conversation

@liamhuber
Copy link
Member

@liamhuber liamhuber commented Aug 31, 2025

Closes #59

I want to play around using it as a decorator, but I'm not yet convinced that the signature will be clean enough to be useful.

EDIT: I don't have time to play around with a decorator format. I'm not closed to it, I'd just rather leave it for later and already get access to what's here.

liamhuber and others added 5 commits August 22, 2025 20:42
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Co-authored-by: Marvin Poul <ponder@creshal.de>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_snippets/exception_context

@codecov
Copy link

codecov bot commented Aug 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.34%. Comparing base (89a29c6) to head (88ea01e).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
+ Coverage   95.12%   95.34%   +0.22%     
==========================================
  Files          14       15       +1     
  Lines         574      602      +28     
==========================================
+ Hits          546      574      +28     
  Misses         28       28              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
not BaseException; for consistency with type hints and between tools

Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Logic is unchanged, but meaning is clearer

Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
on garbage input

Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
@liamhuber liamhuber marked this pull request as ready for review October 2, 2025 17:39
@liamhuber liamhuber requested a review from pmrv October 2, 2025 17:40
@liamhuber liamhuber added the enhancement New feature or request label Oct 2, 2025
@liamhuber liamhuber mentioned this pull request Oct 3, 2025
Copy link
Contributor

@pmrv pmrv left a comment

Choose a reason for hiding this comment

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

Left a suggestion for docs, but otherwise looks good to me.

Comment on lines +139 to +141
... history.append(message)

Callback on all exceptions when no types are specified:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a simple example that shows the use as a plain decorator would be nice, too.

>>> try:
...     with on_error(print, RuntimeError, 42):
...       raise RuntimeError()
... except RuntimeError:
...     pass
42

At least I expect to get the most mileage out of this incarnation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, absolutely. I had misunderstood how much power @contextlib.contextmanager was giving us -- I thought we additionally had to use it inside a regular exit stack.

I agree, many applications will need only a single callback, for which this is a much more condensed syntax 👍

Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
@liamhuber liamhuber merged commit 541f58c into main Oct 4, 2025
20 checks passed
@liamhuber liamhuber deleted the exception_context branch October 4, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception cleanup

2 participants