Skip to content

feat(watcher): add on_callback_error hook to WatchedField and AsyncWatchedField#97

Merged
zeevdr merged 1 commit into
mainfrom
feat/on-callback-error-hook
May 25, 2026
Merged

feat(watcher): add on_callback_error hook to WatchedField and AsyncWatchedField#97
zeevdr merged 1 commit into
mainfrom
feat/on-callback-error-hook

Conversation

@zeevdr
Copy link
Copy Markdown
Member

@zeevdr zeevdr commented May 25, 2026

Summary

  • Users had no way to opt into fail-loud behavior when an on_change callback raised — exceptions were silently logged and discarded.
  • Adds an on_callback_error: Callable[[Exception], None] | None = None parameter to WatchedField, AsyncWatchedField, and their respective field() registration methods, giving callers full control over error handling.
  • When the hook re-raises, the watcher's background loop terminates, enabling crash-on-error semantics.

Test plan

  • test_on_callback_error_hook_is_called — verifies hook receives the exception instead of swallowing it (sync + async)
  • test_on_callback_error_hook_via_field_method — verifies the parameter threads correctly through ConfigWatcher.field() / AsyncConfigWatcher.field() (sync + async)
  • Existing test_callback_exception_is_logged — confirms default behavior (log, no raise) is unchanged
  • Full test suite passes, coverage ≥ 95% maintained

Closes #61

…tchedField

Previously, on_change callback exceptions were silently swallowed and
only logged. Users had no way to opt into fail-loud behavior or custom
error handling.

Add on_callback_error: Callable[[Exception], None] | None = None to
_WatchedFieldBase.__init__, WatchedField.__init__, and
AsyncWatchedField.__init__. Thread the parameter through both
ConfigWatcher.field() and AsyncConfigWatcher.field() so it's accessible
at the call site. When set, the hook is called with the exception
instead of logging. If the hook re-raises, the watcher loop terminates.

Closes #61

Co-Authored-By: Claude <noreply@anthropic.com>
@zeevdr zeevdr added this to the Beta Readiness milestone May 25, 2026
@zeevdr zeevdr added size: S Quick win — a few hours or less priority: P2 Nice-to-have labels May 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@zeevdr zeevdr merged commit 364c38b into main May 25, 2026
15 checks passed
@zeevdr zeevdr deleted the feat/on-callback-error-hook branch May 25, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P2 Nice-to-have size: S Quick win — a few hours or less

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Watcher: optional on_callback_error hook

1 participant