Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observer throws false MobXCaughtException on any exceptions thrown within its scope #905

Closed
subzero911 opened this issue Mar 5, 2023 · 3 comments

Comments

@subzero911
Copy link
Contributor

Example:
image

Here, the error reason is a bad GoRouter configuration, but MobX wraps it into MobXCaughtException.
This makes debugging difficult.

@subzero911 subzero911 changed the title Observer throws false MobXCaughtException on any exceptions thrown within it Observer throws false MobXCaughtException on any exceptions thrown within its scope Mar 5, 2023
@fzyzcjy
Copy link
Collaborator

fzyzcjy commented Mar 5, 2023

You can catch MobXCaughtException and read its .exception field

@subzero911
Copy link
Contributor Author

I can't imagine wrapping every Observer into try-catch.
The only thing that comes to my mind is to use root catcher or runZonedGuarded and check if it's a MobXCaughtException and log to console its inner exception and stacktrace. But do we ever need this MobXCaughtException, if I always unwrap it at the end?
Is it possible to turn off this exception in a config?

@amondnet
Copy link
Collaborator

amondnet commented Mar 6, 2023

@subzero911
https://mobx.netlify.app/api/context#reactiveconfig

disableErrorBoundaries: When true, MobX will not guard against exceptions thrown during reactions. By default, it is false, which means MobX will catch unhandled exceptions and ensure the consistency of the reactive system.

By default, MobX will catch and re-throw exceptions happening in your code to make sure that a reaction in one exception does not prevent the scheduled execution of other, possibly unrelated, reactions. This means exceptions are not propagated back to the original causing code and therefore you won't be able to catch them using try/catch.

By disabling error boundaries, exceptions can escape derivations. This might ease debugging, but might leave MobX and by extension your application in an unrecoverable broken state.

https://mobx.js.org/configuration.html#disableerrorboundaries-boolean

#853

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants