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
def failed(err, reset):
    return html(t"<div><p>Something went wrong: {str(err())}</p><button onclick={reset}>Retry</button></div>")


html(t"<{Errored} fallback={failed}><{Dashboard} /></{Errored}>")
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 node, a zero-arg callable, or a list of either. A node is enough: a component inside it doesn't run until the boundary mounts it, so Errored(Dashboard()) needs no lambda.
  • fallback: a node, 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 read it with err(), in a template expression or anywhere else. 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 the router's url, which changes on every navigation.
from wybthon import Errored, component, html
from wybthon.router import url


def fallback(err, reset):
    return html(t"""
      <div>
        <p>Something went wrong: {err()}</p>
        <button onclick={reset}>Try again</button>
      </div>
    """)


@component
def Page():
    return Errored(
        Dashboard(),
        fallback=fallback,
        on_error=report,
        reset_on=url,
    )

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