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

React (Unhelpfully) Eats Stacktraces #4368

Closed
machineghost opened this issue Jul 14, 2015 · 2 comments
Closed

React (Unhelpfully) Eats Stacktraces #4368

machineghost opened this issue Jul 14, 2015 · 2 comments

Comments

@machineghost
Copy link

If you have a line of code like the following:

new SomeReactComponent({content: this.props.foo.get('bar')})

and this.props.foo doesn't exist, the React code makes it difficult to debug what's going on.

Normally you can ask the Chrome debugger (and other debuggers as well) to pause on an exception, and it will halt the debugger right on that line. You can then mouseover this.props.foo and see that it is undefined.

However, React has this code:

try {
    renderedComponent = this._renderValidatedComponentWithoutOwnerOrContext();
} finally {
    ReactContext.current = previousContext;
    ReactCurrentOwner.current = null;
}

As you can see, any errors that happen during _renderValidatedComponentWithoutOwnerOrContext are swallowed up, losing both the useful stacktrace and the ability for the browser to debug that code.

I understand React needs to do the two lines in the finally to clean up, but it would be helpful if it could save the exception thrown (eg. try{...} catch (e) { var caughtError = e}) and then rethrow it after it has finished the cleanup (eg. throw (caughtError);).

If for some reason that's impossible, an alternative (but less useful) solution would be to log the error (console && console.error(caughtError)). This would at least provide the developer with the stacktrace, although it wouldn't let them debug the error.

@milesj
Copy link
Contributor

milesj commented Jul 14, 2015

Yes please. Swallowed errors are really annoying.

@jimfb
Copy link
Contributor

jimfb commented Jul 17, 2015

That's not how try-finally blocks work. A try-finally block does not swallow an exception.

See: #2626. and #2912, #4199, #2665. etc.

If you can create a simple example in jsfiddle that demonstrates an issue (React swallowing exceptions), I'm happy to re-open and investigate this issue.

On the off chance you're using promises... http://blog.taylormcgann.com/2014/08/21/catch-errors-javascript-promise-chains/

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