Skip to content

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

ErrorBoundary(props: Any) -> Any

Catch render errors in children and display a fallback.

Parameters:

Name Type Description Default
props Any

The component's props with the following keys:

  • fallback: A VNode, a string, or a callable (error, reset) -> VNode. The callable form may also accept just (error,).
  • on_error: Optional callback invoked with the caught exception (errors raised inside the callback are swallowed).
  • reset_key / reset_keys: When this value (or callable result) changes, the boundary auto-clears the current error.
  • children: Children rendered when no error is active.
required

Returns:

Type Description
Any

A reactive VNode subtree that swaps to the

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),
    )
  • fallback receives the error and a reset() callback. Calling reset() clears the error and re-renders the children.
  • An on_error hook (if provided) lets you send the error to your monitoring stack.

See also