Skip to content

Error Boundary

wybthon.error_boundary

error_boundary

Errored: catch render and effect errors in a subtree.

Errored installs an error handler on its owner scope. When a child render, hole, or effect raises, the boundary swaps in a fallback while leaving sibling trees untouched. It's the recommended way to surface unexpected errors without crashing the whole app.

Boundaries heal automatically: the boundary remembers which reactive inputs the failing computation had read, and when any of them changes it re-renders its children. A fixed user_id, a re-fetched memo, or a corrected form field clears the error without an explicit reset(); reset and reset_on remain for manual retries.

The fallback receives the error as an accessor, as in Solid 2.0: call err() to read it.

Example
Errored(
    lambda: Dashboard(),
    fallback=lambda err, reset: div(
        p("Something went wrong: ", lambda: str(err())),
        button("Retry", on_click=reset),
    ),
)
See Also

Functions:

Name Description
Errored

Catch errors raised while rendering children and show a fallback.

Errored

Errored(children: Any = None, *, fallback: Any = None, on_error: Callable[[BaseException], Any] | None = None, reset_on: Any = None) -> VNode

Catch errors raised while rendering children and show a fallback.

Parameters:

Name Type Description Default
children Any

Content rendered while no error is active: a VNode, a zero-arg callable, or a list of either.

None
fallback Any

A VNode, a string, or a callable (err, reset) -> VNode (or (err) -> VNode). err is an accessor for the caught exception; reset() clears the error and re-renders the children.

None
on_error Callable[[BaseException], Any] | None

Optional callback invoked with the caught exception.

None
reset_on Any

An accessor (or plain value) whose change clears the current error automatically, for example the current route.

None

Returns:

Type Description
VNode

A component VNode that swaps to the fallback

VNode

whenever a descendant raises.

What's in this module

Errored installs an error handler on its owner scope. When a descendant component body, hole, prop binding, effect, or action raises, the boundary swaps in a fallback and leaves sibling trees untouched. It's the recommended way to keep one broken widget from taking down the page.

Name Description
Errored Errored(children, *, fallback=None, on_error=None, reset_on=None).
  • children: a VNode, a zero-arg callable, or a list of either.
  • fallback: a VNode, a string, or a callable (err, reset) -> VNode (a one-argument (err) or zero-argument form also works). err is an Accessor for the caught exception, as in Solid 2.0, so call err() to read it. reset() clears the error and re-renders the children. Without a fallback the boundary renders "Something went wrong."
  • on_error: called with the exception (send it to your monitoring).
  • reset_on: an accessor whose change clears the current error automatically, for example current_path.
from wybthon import Errored, button, component, div, p
from wybthon.router import current_path


@component
def Page():
    return Errored(
        lambda: Dashboard(),
        fallback=lambda err, reset: div(
            p(t"Something went wrong: {err}"),
            button("Try again", on_click=reset),
        ),
        on_error=lambda err: report(err),
        reset_on=current_path,
    )

Async memos store an exception raised by their body and re-raise it on read, so a failed fetch inside a Loading surfaces at the nearest Errored too. To handle an effect's error locally instead, pass error=handler to create_effect.

See also