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

More info about error: [mobx] An uncaught exception occurred while... #462

Closed
mweststrate opened this issue Aug 6, 2016 · 7 comments
Closed

Comments

@mweststrate
Copy link
Member

mweststrate commented Aug 6, 2016

This issue further elaborates on the above error, fee free to comment, but note that comments might be cleaned up after discussing

This error signals that an exception is thrown from a reactive function. The exception is not thrown by MobX itself, but from your own code in for example the render() method of an @observer component, the computation of of a @computed value or the function you passed to a reaction like autorun.

Allowing an exception to escape from these methods might lead to unwanted behavior; although MobX in general will continue to work, the throwing method will not be further tracked or automatically run by MobX. So avoid these situations.

The logged message is just a warning that an exception did happen, however it is not the cause. The causing exception is rethrown and should be printed in the log, unless other code (unrelated to MobX) catches the exception.

To get an idea, in MobX handling in exceptions roughly looks like:

function mobxTrackFunction(fn) {
  let hasError = true;
  try {
    const res = fn();
    hasError = false;
    return res;
  } finally {
    if (hasError)
      console.warn("That error message");
  }
}

In other words, if fn() throws; if you will see this message, but it is the symptom of an uncaught exception, but not cause nor the handling of the exception. So you the real exception should end up in your logs directly after this warning, unless the exception is eaten, for example by the catch clause of a promise.

@ericclemmons
Copy link

Another helpful note, be sure that you don't have both a @computed and @observable by the same name.

This is common during refactoring code, and will cause this error. Removing the duplicate definition should resolve it.

@mweststrate
Copy link
Member Author

Heh nice one. Isn't the double declaration not picked up by lint / flow /
typescript btw? Or not using any of those?

Op vr 14 okt. 2016 om 04:07 schreef Eric Clemmons <[email protected]

:

Another helpful note, be sure that you don't have both a @computed and
@observable by the same name
.

This is common during refactoring code, and will cause this error.
Removing the duplicate definition should resolve it.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#462 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABvGhO1HY0-q3IJWtt4g06uRK98OjCxEks5qzuPOgaJpZM4JeSYY
.

@ericclemmons
Copy link

@mweststrate It seems our ESLint rules (based on those from AirBnB) don't see duplicate class properties as a problem.

Anyway, thought it was an interesting edge-case, but it's definitely user-error.

@jorilallo
Copy link

@mweststrate We just deployed a larger project using Mobx but given the complexity, also have higher amount of exceptions. We're using Bugsnag for exception tracking but unfortunately mobx-react completely obfuscating relevant stacktraces for errors in React components. Any recommendation for getting around this?

@mweststrate
Copy link
Member Author

mweststrate commented Oct 20, 2016

@jorilallo In principle that shouldn't happen, there is no error catching in MobX, only cleanup in finally blocks. So apparently something else is eating exceptions. But possible it relates to this issue: mobxjs/mobx-react#134? That PR is in npm available as [email protected]. Could you check whether it makes a difference?

@jorilallo
Copy link

@mweststrate sure, I'll give it a try

@dreisel
Copy link

dreisel commented Jan 17, 2017

working on it

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

4 participants