RFC: onError implemented with events like model #1557
Replies: 1 comment 8 replies
-
Yeah this is an argument for why onError probably is a poor API design. Error Boundaries and Boundaries in general are really designed as UI concern. I wouldn't mind seeing what other reactive libraries have done but I think this probably should be a view thing. Ideally there would only be a single one at a level. From that perspective problem 1 is a shortcoming. You should be able to throw from onError and have it go up to a parent. Funny enough ErrorBoundary Component doesn't suffer from this as if the error happens on Component education it will go up to the next ErrorBoundary. I debated even exposing onError. Because really it is a bit like Suspense.. But I do feel it is more adaptable. Other components should be able to act as Error Boundaries perhaps. The replace all children behavior doesn't have to be the behavior. But the current solution doesn't account for multiple at the same level nor could it. I wonder if it should be more like a component builder that passes error as a signal through the props. const ErrorBoundary = createErrorBoundary((props) => {
return <Show when={props.error} fallback={props.fallback}>
{props.children}
</Show>
}) Etc.. I'm sure reactivity purists like onError exists but I sort of feel like a lot of the reason for it existing is to bound off effects.. I guess that is the other option. Give it a root like API. createErrorRoot(() => {
// only catches things created in here.
}, (err) => // handles error) Both of these are better for the intent I think. Try Catches don't have sibling catches. |
Beta Was this translation helpful? Give feedback.
-
onError
is documented as followingassume that each Component has it's own onError hook.
if an error is triggered in
<SubChild/>
, it will be handled by its own hookif it want to ignore the error, and propagate it up, it is suggested by the docs that we need to rethrow
but in the case of this basic example, throwing in the onError callback, will result in unhandled exception
and the
<Child/>
component will have no opportunity to handle the exception.additionally,
onError
is additive hook, which mean that a component can have multiple handlers at the same error scope.when an error is detected both or all callbacks at that level will be invoked ( in the order they registered )
with the exception if the handler throws, and breaks the exection.
so we have 2 issues
it is therefore proposed, to we provide an more control over error propagation
bubbleError()
a util that will propagate an error up the scope.stopImmidiatePropogation and bubbleError to the parent scope
if handlers on same level wants to communicate, they can mutate the Error Object
but it is important to note, that each handler is technically a standalone, and should be invoked independently
unless user intervened in the natural execution flow
4 votes ·
Beta Was this translation helpful? Give feedback.
All reactions