-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add the possibility to define and pass custom front- and backend event exception handlers to the rx.Config. #5
Add the possibility to define and pass custom front- and backend event exception handlers to the rx.Config. #5
Conversation
…ption handlers to the rx.Config
WalkthroughThe update introduces comprehensive exception handling features across the Reflex framework. It adds new exception handlers for both frontend and backend errors, allows configuration via Changes
Possibly related issues
Poem
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (5)
Files skipped from review as they are similar to previous changes (1)
Additional Context UsedRuff (141)
Additional comments not posted (4)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Out of diff range and nitpick comments (4)
reflex/constants/__init__.py (1)
Line range hint
3-68
: Consider sorting and formatting the import block to improve readability and maintainability.- from .base import ( + from .base import ( COOKIES, ENV_MODE_ENV_VAR, IS_WINDOWS, IS_WINDOWS_BUN_SUPPORTED_MACHINE, # type: ignore LOCAL_STORAGE, POLLING_MAX_HTTP_BUFFER_SIZE, PYTEST_CURRENT_TEST, REFLEX_VAR_CLOSING_TAG, REFLEX_VAR_OPENING_TAG, RELOAD_CONFIG, SKIP_COMPILE_ENV_VAR, ColorMode, Dirs, Env, LogLevel, Next, Ping, Reflex, ReflexHostingCLI, Templates, ) - from .compiler import ( + from .compiler import ( NOCOMPILE_FILE, SETTER_PREFIX, CompileVars, ComponentName, Ext, Hooks, Imports, MemoizationDisposition, MemoizationMode, PageNames, ) - from .config import ( + from .config import ( ALEMBIC_CONFIG, PRODUCTION_BACKEND_URL, Config, Expiration, GitIgnore, RequirementsTxt, ) - from .custom_components import ( + from .custom_components import ( CustomComponents, ) - from .event import Endpoint, EventTriggers, SocketEvent, EventExceptionHandlers + from .event import Endpoint, EventTriggers, SocketEvent, EventExceptionHandlers - from .installer import ( + from .installer import ( Bun, Fnm, Node, PackageJson, ) - from .route import ( + from .route import ( ROUTE_NOT_FOUND, ROUTER, ROUTER_DATA, ROUTER_DATA_INCLUDE, DefaultPage, Page404, RouteArgType, RouteRegex, RouteVar, ) - from .style import STYLES_DIR, Tailwind + from .style import STYLES_DIR, Tailwindreflex/constants/event.py (2)
Line range hint
16-16
: Consider adding a blank line after the "Returns" section in the docstring for consistency.+ """ + Returns: + The path for the endpoint. + """
Line range hint
52-52
: Consider adding a blank line after the "Returns" section in the docstring for consistency.+ """ + Returns: + The event name string. + """reflex/state.py (1)
Line range hint
2494-2592
: Review locking mechanism inStateManagerRedis
.The locking mechanism should ensure that locks are always released, even in cases of exceptions. Consider using a try-finally block to guarantee that locks are released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (2)
reflex/config.py (2)
Line range hint
3-12
: Reformat the import block to maintain a sorted order.
Line range hint
426-426
: Add a blank line after the last section in the docstring for better readability.
…vent exception handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Out of diff range and nitpick comments (20)
tests/test_config.py (7)
Line range hint
1-12
: Consider sorting and formatting the import block for better readability and maintainability.
Line range hint
21-21
: Add a blank line after the "Args" section for better readability.
Line range hint
39-39
: Add a blank line after the "Args" section for better readability.
Line range hint
67-67
: Add a blank line after the "Args" section for better readability.
Line range hint
101-101
: Add a blank line after the "Args" section for better readability.
Line range hint
190-190
: Add a blank line after the "Args" section for better readability.
Line range hint
213-213
: Add a blank line after the "Args" section for better readability.reflex/config.py (13)
Line range hint
3-13
: Consider sorting and formatting the import block for better readability and maintainability.
Line range hint
59-59
: Add a blank line after the "Returns" section for better readability.
Line range hint
89-89
: Add a blank line after the "Returns" section for better readability.
Line range hint
111-111
: Add a blank line after the "Returns" section for better readability.
Line range hint
122-122
: Add a blank line after the "Returns" section for better readability.
Line range hint
221-221
: Add a blank line after the "Args" section for better readability.
Line range hint
247-247
: Add a blank line after the "Returns" section for better readability.
Line range hint
259-259
: Add a blank line after the "Raises" section for better readability.
Line range hint
279-279
: Add a blank line after the "Raises" section for better readability.
Line range hint
316-316
: Add a blank line after the "Returns" section for better readability.
Line range hint
334-334
: Add a blank line after the "Args" section for better readability.
Line range hint
361-361
: Add a blank line after the "Args" section for better readability.
Line range hint
432-432
: Add a blank line after the "Returns" section for better readability.
tests/test_config.py
Outdated
print("Custom Backend Exception") | ||
print(stack) | ||
|
||
class SomeHandler: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SomeHandler
class lacks a docstring. Adding a docstring would improve code documentation and maintainability.
259a260
+ """Handler for processing custom exceptions."""
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
class SomeHandler: | |
class SomeHandler: | |
"""Handler for processing custom exceptions.""" |
tests/test_config.py
Outdated
|
||
class SomeHandler: | ||
|
||
def handle(self, message:str, stack:str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handle
method in SomeHandler
class lacks a docstring. Adding a docstring would improve code documentation and maintainability.
261a262
+ """Handle the exception by logging or other means."""
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def handle(self, message:str, stack:str): | |
def handle(self, message:str, stack:str): | |
"""Handle the exception by logging or other means.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Out of diff range and nitpick comments (2)
tests/test_config.py (2)
290-290
: Add a blank line after the last section in the docstring for consistency.
323-323
: Add a blank line after the last section in the docstring for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Hi @maximvlah awesome! Thanks for your effort. |
reflex/state.py
Outdated
|
||
config = get_config() | ||
|
||
# Call the custom backend exception handler if specified. If not, fallback to the default handler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just passing the whole Exception (variable e
) to the exception handlers instead of only passing 2 strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Out of diff range and nitpick comments (1)
reflex/state.py (1)
1816-1830
: Add a blank line after the last section in the docstring for better readability.
reflex/config.py
Outdated
frontend_exception_handler: Optional[Callable[[str, str], None]] = default_frontend_exception_handler | ||
|
||
# Backend Error Handler Function | ||
backend_exception_handler: Optional[Callable[[str, str], None]] = default_backend_exception_handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that exception handlers do not return any value.
- frontend_exception_handler: Optional[Callable[[str, str], None]] = default_frontend_exception_handler
- backend_exception_handler: Optional[Callable[[str, str], None]] = default_backend_exception_handler
+ frontend_exception_handler: Optional[Callable[[str, str], None]] = None
+ backend_exception_handler: Optional[Callable[[str, str], None]] = None
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
frontend_exception_handler: Optional[Callable[[str, str], None]] = default_frontend_exception_handler | |
# Backend Error Handler Function | |
backend_exception_handler: Optional[Callable[[str, str], None]] = default_backend_exception_handler | |
frontend_exception_handler: Optional[Callable[[str, str], None]] = None | |
# Backend Error Handler Function | |
backend_exception_handler: Optional[Callable[[str, str], None]] = None |
reflex/config.py
Outdated
def _validate_exception_handlers(self): | ||
"""Validate the custom event exception handlers for front- and backend. | ||
|
||
Raises: | ||
ValueError: If the custom exception handlers are invalid. | ||
|
||
""" | ||
for handler_domain, handler_fn, handler_spec in zip( | ||
["frontend", "backend"], | ||
[self.frontend_exception_handler, self.backend_exception_handler], | ||
[ | ||
constants.EventExceptionHandlers.FRONTEND_ARG_SPEC, | ||
constants.EventExceptionHandlers.BACKEND_ARG_SPEC, | ||
], | ||
): | ||
if hasattr(handler_fn, "__name__"): | ||
_fn_name = handler_fn.__name__ | ||
else: | ||
_fn_name = handler_fn.__class__.__name__ | ||
|
||
if isinstance(handler_fn, functools.partial): | ||
raise ValueError( | ||
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a partial function. Please provide a named function instead." | ||
) | ||
|
||
if not callable(handler_fn): | ||
raise ValueError( | ||
f"Provided custom {handler_domain} exception handler `{_fn_name}` is not a function." | ||
) | ||
|
||
# Allow named functions only as lambda functions cannot be introspected | ||
if _fn_name == "<lambda>": | ||
raise ValueError( | ||
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a lambda function. Please use a named function instead." | ||
) | ||
|
||
# Check if the function has the necessary annotations and types | ||
arg_annotations = inspect.get_annotations(handler_fn) | ||
|
||
for required_arg in handler_spec: | ||
if required_arg not in arg_annotations: | ||
raise ValueError( | ||
f"Provided custom {handler_domain} exception handler `{_fn_name}` does not take the required argument `{required_arg}`" | ||
) | ||
|
||
if arg_annotations[required_arg] != handler_spec[required_arg]: | ||
raise ValueError( | ||
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong type for {required_arg} argument." | ||
f"Expected `{handler_spec[required_arg]}` but got `{arg_annotations[required_arg]}`" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor the validation logic to use early return pattern for better readability.
- if hasattr(handler_fn, "__name__"):
- _fn_name = handler_fn.__name__
- else:
- _fn_name = handler_fn.__class__.__name__
+ _fn_name = getattr(handler_fn, '__name__', handler_fn.__class__.__name__)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def _validate_exception_handlers(self): | |
"""Validate the custom event exception handlers for front- and backend. | |
Raises: | |
ValueError: If the custom exception handlers are invalid. | |
""" | |
for handler_domain, handler_fn, handler_spec in zip( | |
["frontend", "backend"], | |
[self.frontend_exception_handler, self.backend_exception_handler], | |
[ | |
constants.EventExceptionHandlers.FRONTEND_ARG_SPEC, | |
constants.EventExceptionHandlers.BACKEND_ARG_SPEC, | |
], | |
): | |
if hasattr(handler_fn, "__name__"): | |
_fn_name = handler_fn.__name__ | |
else: | |
_fn_name = handler_fn.__class__.__name__ | |
if isinstance(handler_fn, functools.partial): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a partial function. Please provide a named function instead." | |
) | |
if not callable(handler_fn): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is not a function." | |
) | |
# Allow named functions only as lambda functions cannot be introspected | |
if _fn_name == "<lambda>": | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a lambda function. Please use a named function instead." | |
) | |
# Check if the function has the necessary annotations and types | |
arg_annotations = inspect.get_annotations(handler_fn) | |
for required_arg in handler_spec: | |
if required_arg not in arg_annotations: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` does not take the required argument `{required_arg}`" | |
) | |
if arg_annotations[required_arg] != handler_spec[required_arg]: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong type for {required_arg} argument." | |
f"Expected `{handler_spec[required_arg]}` but got `{arg_annotations[required_arg]}`" | |
) | |
def _validate_exception_handlers(self): | |
"""Validate the custom event exception handlers for front- and backend. | |
Raises: | |
ValueError: If the custom exception handlers are invalid. | |
""" | |
for handler_domain, handler_fn, handler_spec in zip( | |
["frontend", "backend"], | |
[self.frontend_exception_handler, self.backend_exception_handler], | |
[ | |
constants.EventExceptionHandlers.FRONTEND_ARG_SPEC, | |
constants.EventExceptionHandlers.BACKEND_ARG_SPEC, | |
], | |
): | |
_fn_name = getattr(handler_fn, '__name__', handler_fn.__class__.__name__) | |
if isinstance(handler_fn, functools.partial): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a partial function. Please provide a named function instead." | |
) | |
if not callable(handler_fn): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is not a function." | |
) | |
# Allow named functions only as lambda functions cannot be introspected | |
if _fn_name == "<lambda>": | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a lambda function. Please use a named function instead." | |
) | |
# Check if the function has the necessary annotations and types | |
arg_annotations = inspect.get_annotations(handler_fn) | |
for required_arg in handler_spec: | |
if required_arg not in arg_annotations: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` does not take the required argument `{required_arg}`" | |
) | |
if arg_annotations[required_arg] != handler_spec[required_arg]: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong type for {required_arg} argument." | |
f"Expected `{handler_spec[required_arg]}` but got `{arg_annotations[required_arg]}`" | |
) |
Consider using the early return pattern to simplify the validation logic.
- if isinstance(handler_fn, functools.partial):
- raise ValueError(...)
- if not callable(handler_fn):
- raise ValueError(...)
- if _fn_name == "<lambda>":
- raise ValueError(...)
+ if isinstance(handler_fn, functools.partial):
+ raise ValueError(...)
+ if not callable(handler_fn):
+ raise ValueError(...)
+ if _fn_name == "<lambda>":
+ raise ValueError(...)
+ return # Early return after validations
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def _validate_exception_handlers(self): | |
"""Validate the custom event exception handlers for front- and backend. | |
Raises: | |
ValueError: If the custom exception handlers are invalid. | |
""" | |
for handler_domain, handler_fn, handler_spec in zip( | |
["frontend", "backend"], | |
[self.frontend_exception_handler, self.backend_exception_handler], | |
[ | |
constants.EventExceptionHandlers.FRONTEND_ARG_SPEC, | |
constants.EventExceptionHandlers.BACKEND_ARG_SPEC, | |
], | |
): | |
if hasattr(handler_fn, "__name__"): | |
_fn_name = handler_fn.__name__ | |
else: | |
_fn_name = handler_fn.__class__.__name__ | |
if isinstance(handler_fn, functools.partial): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a partial function. Please provide a named function instead." | |
) | |
if not callable(handler_fn): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is not a function." | |
) | |
# Allow named functions only as lambda functions cannot be introspected | |
if _fn_name == "<lambda>": | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a lambda function. Please use a named function instead." | |
) | |
# Check if the function has the necessary annotations and types | |
arg_annotations = inspect.get_annotations(handler_fn) | |
for required_arg in handler_spec: | |
if required_arg not in arg_annotations: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` does not take the required argument `{required_arg}`" | |
) | |
if arg_annotations[required_arg] != handler_spec[required_arg]: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong type for {required_arg} argument." | |
f"Expected `{handler_spec[required_arg]}` but got `{arg_annotations[required_arg]}`" | |
) | |
def _validate_exception_handlers(self): | |
"""Validate the custom event exception handlers for front- and backend. | |
Raises: | |
ValueError: If the custom exception handlers are invalid. | |
""" | |
for handler_domain, handler_fn, handler_spec in zip( | |
["frontend", "backend"], | |
[self.frontend_exception_handler, self.backend_exception_handler], | |
[ | |
constants.EventExceptionHandlers.FRONTEND_ARG_SPEC, | |
constants.EventExceptionHandlers.BACKEND_ARG_SPEC, | |
], | |
): | |
if hasattr(handler_fn, "__name__"): | |
_fn_name = handler_fn.__name__ | |
else: | |
_fn_name = handler_fn.__class__.__name__ | |
if isinstance(handler_fn, functools.partial): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a partial function. Please provide a named function instead." | |
) | |
if not callable(handler_fn): | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is not a function." | |
) | |
# Allow named functions only as lambda functions cannot be introspected | |
if _fn_name == "<lambda>": | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` is a lambda function. Please use a named function instead." | |
) | |
return # Early return after validations | |
# Check if the function has the necessary annotations and types | |
arg_annotations = inspect.get_annotations(handler_fn) | |
for required_arg in handler_spec: | |
if required_arg not in arg_annotations: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` does not take the required argument `{required_arg}`" | |
) | |
if arg_annotations[required_arg] != handler_spec[required_arg]: | |
raise ValueError( | |
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong type for {required_arg} argument." | |
f"Expected `{handler_spec[required_arg]}` but got `{arg_annotations[required_arg]}`" | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Out of diff range and nitpick comments (6)
tests/test_config.py (6)
Line range hint
21-21
: Add a blank line after the "Args" section for better readability.
Line range hint
39-39
: Add a blank line after the "Args" section for better readability.
Line range hint
67-67
: Add a blank line after the "Args" section for better readability.
Line range hint
101-101
: Add a blank line after the "Args" section for better readability.
Line range hint
190-190
: Add a blank line after the "Args" section for better readability.
Line range hint
213-213
: Add a blank line after the "Args" section for better readability.
print(stack) | ||
|
||
|
||
class SomeHandler: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a docstring to the SomeHandler
class to improve code documentation and maintainability.
236a237
+ """Handler for processing custom exceptions."""
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
class SomeHandler: | |
class SomeHandler: | |
"""Handler for processing custom exceptions.""" |
|
||
|
||
class SomeHandler: | ||
def handle(self, message: str, stack: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a docstring to the handle
method in the SomeHandler
class to improve code documentation and maintainability.
237a238
+ """Handle the exception by logging or other means."""
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def handle(self, message: str, stack: str): | |
def handle(self, message: str, stack: str): | |
"""Handle the exception by logging or other means.""" |
tests/test_config.py
Outdated
try: | ||
rx.Config(app_name="a", backend_exception_handler=handler_obj["fn"]) | ||
fn_is_valid = True | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unused local variable e
in the except block to clean up the code.
311c312
- except Exception as e:
+ except Exception:
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
except Exception as e: | |
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 11
Out of diff range and nitpick comments (18)
tests/test_config.py (6)
Line range hint
22-22
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
40-40
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
68-68
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
102-102
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
191-191
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
214-214
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
reflex/config.py (12)
Line range hint
63-63
: Add a blank line after the last section ("Returns") for better readability and adherence to PEP 257.+
Line range hint
93-93
: Add a blank line after the last section ("Returns") for better readability and adherence to PEP 257.+
Line range hint
115-115
: Add a blank line after the last section ("Returns") for better readability and adherence to PEP 257.+
Line range hint
126-126
: Add a blank line after the last section ("Returns") for better readability and adherence to PEP 257.+
Line range hint
229-229
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
255-255
: Add a blank line after the last section ("Returns") for better readability and adherence to PEP 257.+
Line range hint
267-267
: Add a blank line after the last section ("Raises") for better readability and adherence to PEP 257.+
Line range hint
287-287
: Add a blank line after the last section ("Raises") for better readability and adherence to PEP 257.+
Line range hint
324-324
: Add a blank line after the last section ("Returns") for better readability and adherence to PEP 257.+
Line range hint
342-342
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
369-369
: Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.+
Line range hint
437-437
: Add a blank line after the last section ("Returns") for better readability and adherence to PEP 257.+
from reflex.config import get_config | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider sorting imports to improve readability and maintainability.
- from reflex.config import get_config
+ from reflex.config import get_config
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
from reflex.config import get_config | |
from reflex.config import get_config | |
def handle_frontend_exception(self, message: str, stack: str) -> None: | ||
"""Handle frontend exceptions. | ||
|
||
If a frontend exception handler is provided, it will be called. | ||
Otherwise, the default frontend exception handler will be called. | ||
|
||
Args: | ||
message: The message of the exception. | ||
stack: The stack trace of the exception. | ||
|
||
""" | ||
config = get_config() | ||
|
||
config.frontend_exception_handler(message=message, stack=stack) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure the frontend_exception_handler
is callable before invoking it to prevent runtime errors.
+ if callable(config.frontend_exception_handler):
config.frontend_exception_handler(message=message, stack=stack)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def handle_frontend_exception(self, message: str, stack: str) -> None: | |
"""Handle frontend exceptions. | |
If a frontend exception handler is provided, it will be called. | |
Otherwise, the default frontend exception handler will be called. | |
Args: | |
message: The message of the exception. | |
stack: The stack trace of the exception. | |
""" | |
config = get_config() | |
config.frontend_exception_handler(message=message, stack=stack) | |
def handle_frontend_exception(self, message: str, stack: str) -> None: | |
"""Handle frontend exceptions. | |
If a frontend exception handler is provided, it will be called. | |
Otherwise, the default frontend exception handler will be called. | |
Args: | |
message: The message of the exception. | |
stack: The stack trace of the exception. | |
""" | |
config = get_config() | |
if callable(config.frontend_exception_handler): | |
config.frontend_exception_handler(message=message, stack=stack) | |
reflex/state.py
Outdated
except Exception as e: | ||
stack_trace = traceback.format_exc() | ||
|
||
config = get_config() | ||
|
||
config.backend_exception_handler(message=str(e), stack=stack_trace) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure the backend_exception_handler
is callable before invoking it to prevent runtime errors.
+ if callable(config.backend_exception_handler):
config.backend_exception_handler(message=str(e), stack=stack_trace)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
except Exception as e: | |
stack_trace = traceback.format_exc() | |
config = get_config() | |
config.backend_exception_handler(message=str(e), stack=stack_trace) | |
except Exception as e: | |
stack_trace = traceback.format_exc() | |
config = get_config() | |
if callable(config.backend_exception_handler): | |
config.backend_exception_handler(message=str(e), stack=stack_trace) |
from __future__ import annotations | ||
|
||
from typing import Generator | ||
from unittest.mock import AsyncMock | ||
|
||
import pytest | ||
|
||
import time | ||
|
||
from reflex.app import process | ||
from reflex.event import Event | ||
from reflex.state import StateManagerRedis | ||
|
||
from reflex.testing import AppHarness | ||
from reflex.config import get_config | ||
|
||
from typing import Generator | ||
|
||
import pytest | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.remote.webdriver import WebDriver | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
|
||
def TestApp(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort and format the import block for better readability and maintainability.
- from typing import Generator
- from unittest.mock import AsyncMock
- import pytest
- import time
- from reflex.app import process
- from reflex.event import Event
- from reflex.state import StateManagerRedis
- from reflex.testing import AppHarness
- from reflex.config import get_config
- from typing import Generator
- import pytest
- from selenium.webdriver.common.by import By
- from selenium.webdriver.remote.webdriver import WebDriver
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
+ from __future__ import annotations
+ import time
+ import pytest
+ from unittest.mock import AsyncMock
+ from typing import Generator
+ from selenium.webdriver.common.by import By
+ from selenium.webdriver.remote.webdriver import WebDriver
+ from selenium.webdriver.support.ui import WebDriverWait
+ from selenium.webdriver.support import expected_conditions as EC
+ from reflex.app import process
+ from reflex.event import Event
+ from reflex.state import StateManagerRedis
+ from reflex.testing import AppHarness
+ from reflex.config import get_config
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
from __future__ import annotations | |
from typing import Generator | |
from unittest.mock import AsyncMock | |
import pytest | |
import time | |
from reflex.app import process | |
from reflex.event import Event | |
from reflex.state import StateManagerRedis | |
from reflex.testing import AppHarness | |
from reflex.config import get_config | |
from typing import Generator | |
import pytest | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.remote.webdriver import WebDriver | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
def TestApp(): | |
from __future__ import annotations | |
import time | |
import pytest | |
from unittest.mock import AsyncMock | |
from typing import Generator | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.remote.webdriver import WebDriver | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from reflex.app import process | |
from reflex.event import Event | |
from reflex.state import StateManagerRedis | |
from reflex.testing import AppHarness | |
from reflex.config import get_config | |
def TestApp(): |
from reflex.testing import AppHarness | ||
from reflex.config import get_config | ||
|
||
from typing import Generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the redundant import of Generator
to avoid confusion and maintain clean code.
- from typing import Generator
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
from typing import Generator |
|
||
|
||
def TestApp(): | ||
"""A test app for event exception handler integration.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the blank line after the function docstring to adhere to PEP 257.
-
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
"""A test app for event exception handler integration.""" | |
"""A test app for event exception handler integration.""" |
Args: | ||
c: The number of times to increment. | ||
|
||
Yields: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line after the last section ("Yields") for better readability and adherence to PEP 257.
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Yields: | |
Yields: | |
Args: | ||
tmp_path_factory: pytest tmp_path_factory fixture | ||
|
||
Yields: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line after the last section ("Yields") for better readability and adherence to PEP 257.
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Yields: | |
Yields: | |
Args: | ||
test_app: harness for TestApp app | ||
|
||
Yields: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line after the last section ("Yields") for better readability and adherence to PEP 257.
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Yields: | |
Yields: | |
We send an event containing a call to a non-existent function in the frontend. | ||
This should trigger the default frontend exception handler. | ||
|
||
Args: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line after the last section ("Args") for better readability and adherence to PEP 257.
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Args: | |
Args: | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (32)
reflex/utils/exceptions.py (1)
47-47
: Add a blank line after the "Returns" section in the docstring for consistency.reflex/state.py (31)
Line range hint
44-65
: Consider sorting and formatting the import block for better readability and maintainability.- from reflex import constants - from reflex.base import Base - from reflex.event import ( - Event, - EventHandler, - EventSpec, - fix_events, - window_alert, - ) - from reflex.utils import console, format, prerequisites, types - from reflex.utils.exceptions import ImmutableStateError, LockExpiredError - from reflex.utils.exec is_testing_env - from reflex.utils.serializers import SerializedType, serialize, serializer - from reflex.vars import BaseVar, ComputedVar, Var, computed_var + from reflex import constants + from reflex.base import Base + from reflex.event import ( + Event, + EventHandler, + EventSpec, + fix_events, + ) + from reflex.utils import console, format, prerequisites, types + from reflex.utils.exceptions import ImmutableStateError, LockExpiredError + from reflex.utils.exec import is_testing_env + from reflex.utils.serializers import SerializedType, serialize, serializer + from reflex.vars import BaseVar, ComputedVar, Var, computed_var
Line range hint
54-54
: The importwindow_alert
fromreflex.event
is unused and should be removed to clean up the code.- from reflex.event import ( - Event, - EventHandler, - EventSpec, - fix_events, - window_alert, - ) + from reflex.event import ( + Event, + EventHandler, + EventSpec, + fix_events, + )
Line range hint
96-96
: Add a blank line after the last section ("Args") in the docstring of the method_no_chain_background_task
to adhere to PEP 257 docstring conventions.
Line range hint
118-118
: Add a blank line after the last section ("Args") in the docstring of the method_substate_key
to adhere to PEP 257 docstring conventions.
Line range hint
141-141
: Add a blank line after the last section ("Args") in the docstring of the method_split_substate_key
to adhere to PEP 257 docstring conventions.
Line range hint
161-161
: Add a blank line after the last section ("Args") in the docstring of the method__init__
to adhere to PEP 257 docstring conventions.
Line range hint
183-183
: Add a blank line after the last section ("Raises") in the docstring of the method__repr__
to adhere to PEP 257 docstring conventions.
Line range hint
228-228
: Add a blank line after the last section ("Returns") in the docstring of the method_get_computed_vars
to adhere to PEP 257 docstring conventions.
Line range hint
246-246
: Add a blank line after the last section ("Returns") in the docstring of the method__init_subclass__
to adhere to PEP 257 docstring conventions.
Line range hint
335-335
: Add a blank line after the last section ("Raises") in the docstring of the method_copy_fn
to adhere to PEP 257 docstring conventions.
Line range hint
366-366
: Add a blank line after the last section ("Returns") in the docstring of the method_item_is_event_handler
to adhere to PEP 257 docstring conventions.
Line range hint
375-375
: Add a blank line after the last section ("Returns") in the docstring of the method_mixins
to adhere to PEP 257 docstring conventions.
Line range hint
393-393
: Add a blank line after the last section ("Raises") in the docstring of the method_init_var_dependency_dicts
to adhere to PEP 257 docstring conventions.
Line range hint
520-520
: Add a blank line after the last section ("Returns") in the docstring of the method_check_overridden_methods
to adhere to PEP 257 docstring conventions.
Line range hint
541-541
: Add a blank line after the last section ("Returns") in the docstring of the methodget_skip_vars
to adhere to PEP 257 docstring conventions.
Line range hint
555-555
: Add a blank line after the last section ("Returns") in the docstring of the methodget_parent_state
to adhere to PEP 257 docstring conventions.
Line range hint
623-623
: Add a blank line after the last section ("Raises") in the docstring of the methodget_substates
to adhere to PEP 257 docstring conventions.
Line range hint
646-646
: Add a blank line after the last section ("Returns") in the docstring of the methodget_name
to adhere to PEP 257 docstring conventions.
Line range hint
666-666
: Add a blank line after the last section ("Returns") in the docstring of the methodget_full_name
to adhere to PEP 257 docstring conventions.
Line range hint
681-681
: Add a blank line after the last section ("Returns") in the docstring of the methodget_class_substate
to adhere to PEP 257 docstring conventions.
Line range hint
691-691
: Add a blank line after the last section ("Returns") in the docstring of the methodget_class_var
to adhere to PEP 257 docstring conventions.
Line range hint
701-701
: Add a blank line after the last section ("Returns") in the docstring of the method_init_var
to adhere to PEP 257 docstring conventions.
Line range hint
721-721
: Add a blank line after the last section ("Raises") in the docstring of the methodadd_var
to adhere to PEP 257 docstring conventions.
Line range hint
748-748
: Add a blank line after the last section ("Raises") in the docstring of the method_set_var
to adhere to PEP 257 docstring conventions.
Line range hint
764-764
: Add a blank line after the last section ("Raises") in the docstring of the method_create_event_handler
to adhere to PEP 257 docstring conventions.
Line range hint
790-790
: Add a blank line after the last section ("Raises") in the docstring of the method_create_setter
to adhere to PEP 257 docstring conventions.
Line range hint
822-822
: Add a blank line after the last section ("Args") in the docstring of the method_set_default_value
to adhere to PEP 257 docstring conventions.
Line range hint
834-834
: Add a blank line after the last section ("Returns") in the docstring of the method_get_base_functions
to adhere to PEP 257 docstring conventions.
Line range hint
843-843
: Add a blank line after the last section ("Args") in the docstring of the methodget_token
to adhere to PEP 257 docstring conventions.
Line range hint
856-856
: Add a blank line after the last section ("Args") in the docstring of the methodget_sid
to adhere to PEP 257 docstring conventions.
Line range hint
878-878
: Add a blank line after the last section ("Returns") in the docstring of the methodget_headers
to adhere to PEP 257 docstring conventions.
@maximvlah avoid using the |
Hello, Reflex maintainer here. We've recently started looking into solving this specific issue of picking up frontend errors and being able to handle them on the backend. What is your plan regarding this PR? |
Hey @Lendemor, thanks for checking in. @maximvlah will continue to work on this on 10.06. |
@Lendemor continue here: reflex-dev#3476 |
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests
Refactor