Skip to content

feat: nullable exception handlers #5703

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

maximvlah
Copy link
Contributor

@maximvlah maximvlah commented Aug 11, 2025

Closes #3776

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR introduces nullable exception handlers for both frontend and backend error handling in the Reflex framework. The changes allow users to explicitly set exception handlers to None to disable custom exception handling, which is particularly useful for Kubernetes liveness and readiness probes where standard HTTP error responses are preferred over custom error handling logic.

The implementation modifies two core files:

In reflex/app.py:

  • Updates type annotations for frontend_exception_handler and backend_exception_handler to include | None
  • Modifies validation logic to skip validation when handlers are None
  • Adds a null check before executing the backend exception handler

In reflex/state.py:

  • Adds null checks in the _process_event method before calling backend_exception_handler
  • Adds null checks in the handle_frontend_exception method before calling frontend_exception_handler

The change maintains full backward compatibility since the default handlers are still provided, but adds flexibility for cloud-native deployments where infrastructure monitoring systems need predictable error responses. This fits into the broader Reflex architecture by extending the existing exception handling system without breaking existing functionality, allowing apps to have optional exception handlers that can be conditionally disabled based on deployment context.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it maintains backward compatibility while adding useful functionality
  • Score reflects well-structured null safety checks and non-breaking changes to existing exception handling
  • Pay close attention to the validation logic in reflex/app.py to ensure the skip condition works correctly

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

Copy link

codspeed-hq bot commented Aug 11, 2025

CodSpeed Performance Report

Merging #5703 will not alter performance

Comparing maximvlah:set-none-to-exception-handler (7ceac10) with main (9b2d93e)

Summary

✅ 8 untouched benchmarks

@maximvlah
Copy link
Contributor Author

@masenf @benedikt-bartscher ready for review

reflex/state.py Outdated
event_specs = (
prerequisites.get_and_validate_app().app.backend_exception_handler(ex)
app.backend_exception_handler(ex)
if app.backend_exception_handler
Copy link
Member

Choose a reason for hiding this comment

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

it would be a tad better to check with is not None just in case a Var might come here, otherwise looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adhami3310 thx, just fixed it

adhami3310
adhami3310 previously approved these changes Aug 13, 2025
@adhami3310
Copy link
Member

the only issue is that this doesn't disable the frontend onError from triggering, it just that when it goes to the backend, it does nothing

Copy link
Contributor

@benedikt-bartscher benedikt-bartscher left a comment

Choose a reason for hiding this comment

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

the only issue is that this doesn't disable the frontend onError from triggering, it just that when it goes to the backend, it does nothing

That was the original intention/idea in #3776. Can you adjust it @maximvlah?

@adhami3310 adhami3310 dismissed their stale review August 13, 2025 22:55

onError would still trigger, just the backend will do the equiv of lambda _: None, so nothing would meaningfully change for that

it's quite difficult to pipe the logic through the default error handler :/

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

seems fine to me, are we wanting to disable the entire frontend exception handling mechanism if the handler is None? because that's definitely more work

@adhami3310
Copy link
Member

i think to truly resolve the associated ticket, we do want to actually disable onError

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.

Allow to disable frontend exception handler with None
4 participants