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

ReactAndroid: JS errors during bundle load were reported as UnknownCppException #24648

Closed
wants to merge 1 commit into from

Conversation

EmielM
Copy link
Contributor

@EmielM EmielM commented Apr 29, 2019

Summary

This fixes a regression on Android introduced by f3e5cce where JS errors thrown during bundle load were lost (shown only as UnknownCppException). It is especially tough to debug (custom) bundling errors without seeing the javascript error.

Root cause hypothesis: since switching to clang, JSErrors thrown in ReactCommon's JSCRuntime::checkException were never matched as std::exception in ReactAndroid's convertCppExceptionToJavaException due to these missing flags.

I'm a bit shy on low-level details concerning how C++ rtti works exactly around catching exceptions thrown in other libraries. All I can say that with this change, a bundle.android.js that only contains throw new Error("wtf"); now nicely outputs a message and stack trace in the logcat. Before (and since @DanielZlotin's switch to clang) it just outputted:

2019-04-29 12:17:59.365 1162-1306/com.rntest E/unknown:ReactNative: Exception in native call
    com.facebook.jni.UnknownCppException: Unknown
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:214)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:764)

Changelog

[Android] [Fixed] - JS errors during bundle load were reported as UnknownCppException.

Test Plan

Might be tricky to test, although an end-to-end on an Android emulator test that checks the logcat for a proper JS stacktrace when the bundle contains invalid JS. No idea if there is infrastructure in place to add this. Any hints?

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 29, 2019
@EmielM EmielM changed the title ReactAndroid: add -fexceptions -frtti to jni CFLAGS ReactAndroid: JS errors during bundle load were reported as UnknownCppException Apr 29, 2019
@react-native-bot react-native-bot added the Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. label Apr 29, 2019
@cpojer
Copy link
Contributor

cpojer commented Apr 29, 2019

Could you rebase this PR on master?

This fixes a regression on Android introduced by f3e5cce where JS errors
thrown during bundle load were lost (shown only as UnknownCppException).
It is especially tough to debug (custom) bundling errors without seeing
the javascript error.

Root cause hypothesis: since switching to clang, JSErrors thrown in
ReactCommon's JSCRuntime::checkException were never matched as
std::exception in Android's convertCppExceptionToJavaException due
to these missing flags.
@EmielM
Copy link
Contributor Author

EmielM commented Apr 29, 2019

Ah, apologies, I wasn't aware github actually tracks updates to the origin. I've rebased.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdvacca is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by Emiel Mols in 6f6696f.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 29, 2019
grabbou pushed a commit that referenced this pull request May 6, 2019
…pException (#24648)

Summary:
This fixes a regression on Android introduced by f3e5cce where JS errors thrown during bundle load were lost (shown only as UnknownCppException). It is especially tough to debug (custom) bundling errors without seeing the javascript error.

Root cause hypothesis: since switching to clang, `JSError`s thrown in ReactCommon's `JSCRuntime::checkException` were never matched as `std::exception` in ReactAndroid's `convertCppExceptionToJavaException` due to these missing flags.

I'm a bit shy on low-level details concerning how C++ rtti works exactly around catching exceptions thrown in other libraries. All I can say that with this change, a `bundle.android.js` that only contains `throw new Error("wtf");` now nicely outputs a message and stack trace in the logcat. Before (and since DanielZlotin's switch to clang) it just outputted:

```
2019-04-29 12:17:59.365 1162-1306/com.rntest E/unknown:ReactNative: Exception in native call
    com.facebook.jni.UnknownCppException: Unknown
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:214)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:764)
```

[Android] [Fixed] - JS errors during bundle load were reported as UnknownCppException.
Pull Request resolved: #24648

Differential Revision: D15123525

Pulled By: mdvacca

fbshipit-source-id: 74b5ce9ebae38d172446b6e31739d795c601947b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants