Error Boundary
wybthon.error_boundary¶
error_boundary
¶
ErrorBoundary component for catching render errors in subtrees.
ErrorBoundary is a function component that
installs an error handler on its owner scope. When a child render or
effect raises, the boundary swaps in a fallback while leaving sibling
trees untouched. It is the recommended way to surface unexpected
errors without crashing the whole app.
See Also
Functions:
| Name | Description |
|---|---|
ErrorBoundary |
Catch render errors in children and display a fallback. |
ErrorBoundary
¶
Catch render errors in children and display a fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
props
|
Any
|
The component's props with the following keys:
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
A reactive |
Any
|
fallback whenever a child raises. |
What's in this module¶
ErrorBoundary catches render errors in its
descendant subtree and renders a fallback in their place. Use it to
isolate failures so a single broken widget can't take down the rest of
the page.
Usage¶
from wybthon import ErrorBoundary, component
from wybthon.html import button, div, p
@component
def Profile(user_id):
raise RuntimeError("not implemented")
@component
def Page():
return ErrorBoundary(
fallback=lambda err, reset: div(
p("Something went wrong: ", str(err)),
button("Try again", on_click=lambda _e: reset()),
),
children=lambda: Profile(user_id=42),
)
fallbackreceives the error and areset()callback. Callingreset()clears the error and re-renders the children.- An
on_errorhook (if provided) lets you send the error to your monitoring stack.