Commit 7af6cb4
add default early JS error handler (facebook#44884)
Summary:
Pull Request resolved: facebook#44884
Removing JavaScript error handler supplied to ReactHostImpl.java which is just a stub and creating a default private handler in ReactInstance.java that routes exception to `NativeExceptionsManager`
Changelog: [Android][BREAKING] Removing `ReactJsExceptionHandler` param from ReactHostImpl() constructor and providing a default private implementation
**Internal:**
- Provide default error handler that can handle early JavaScript error
**Motivation**
When app bundle is being loading and before JavaScript side error handling logic is executed, error that occur in between may be lost or not reported. Native code does have various `try/catch` statements to catch errors but in Android the error handler callback is implemented to be passed in while instantiating `ReactHostImpl` where many cases, including OSS, are just stub implementation that does not do anything.
__The goal of this diff is to add a default error handler that can be used by both OSS and intern.__
When the JavaScript side error handling is fully setup any JavaScript error is routed to LogBox.
For early errors, we want to utilize the native RedBox to display errors.
Longer term goal is to have a single native pipeline but this diff is just to cover the early JS errors until this is realized.
**Implementation details**
The code changes were taken from previously abandoned diff by RSNara (D55439412).
- **Previous**
- `ReactJsExceptionHandler` (often just a stub) is created in Java and passed into `ReactHostImpl`.
- **Updated**
- `DefaultReactJsExceptionHandler` defined in `ReactInstance.java` is instantiated and passed into JNI/C++ via `initHybrid()` call.
- `ReactJsExceptionHandler.reportJsException()` method is removed from `FbReactExceptionManager` as we are not using the default implementation above.
**Related questions**
ThreadQueue in Java uses a separate error handler. Question is if there a good reason for having a separate error handler of if we can combine this into a single error handler.
Also since ThreadQueues are implemented in Java, there is a question of supporting the error handling via native C++ would be feasible or desirable.
**Testing**
You use the following preview diff to `throw Error` before error handling code is run during JavaScript bundle setup. It also includes Android log to check the method was called.
`jf get --version 229685487`
Testing was done using `fb4a` and `rntester-android`.
**Note on inconsistent exception message in `rntester-android`**.
Currently the only the first exception is displayed in RedBox and rest are ignored. Depending on the timing, early js exception is reported or `SurfaceRegistryBinding::startSurface()` is shown. This seems to be more related to clean up when `ReactInstance.loadJSScript()` throws and is not covered in this diff.
Differential Revision: D583857671 parent b19bf2b commit 7af6cb4
5 files changed
Lines changed: 53 additions & 21 deletions
File tree
- packages/react-native/ReactAndroid
- api
- src
- main/java/com/facebook/react
- defaults
- runtime
- test/java/com/facebook/react/runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3778 | 3778 | | |
3779 | 3779 | | |
3780 | 3780 | | |
3781 | | - | |
3782 | | - | |
| 3781 | + | |
| 3782 | + | |
3783 | 3783 | | |
3784 | 3784 | | |
3785 | 3785 | | |
| |||
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | | - | |
78 | | - | |
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
| |||
85 | 82 | | |
86 | 83 | | |
87 | 84 | | |
88 | | - | |
89 | 85 | | |
90 | 86 | | |
91 | 87 | | |
| |||
Lines changed: 0 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
| |||
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
106 | 104 | | |
107 | 105 | | |
108 | 106 | | |
| |||
143 | 141 | | |
144 | 142 | | |
145 | 143 | | |
146 | | - | |
147 | 144 | | |
148 | 145 | | |
149 | 146 | | |
150 | 147 | | |
151 | 148 | | |
152 | 149 | | |
153 | 150 | | |
154 | | - | |
155 | 151 | | |
156 | 152 | | |
157 | 153 | | |
| |||
162 | 158 | | |
163 | 159 | | |
164 | 160 | | |
165 | | - | |
166 | 161 | | |
167 | 162 | | |
168 | 163 | | |
169 | 164 | | |
170 | 165 | | |
171 | 166 | | |
172 | 167 | | |
173 | | - | |
174 | 168 | | |
175 | 169 | | |
176 | 170 | | |
| |||
1067 | 1061 | | |
1068 | 1062 | | |
1069 | 1063 | | |
1070 | | - | |
1071 | 1064 | | |
1072 | 1065 | | |
1073 | 1066 | | |
| |||
Lines changed: 50 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| |||
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
| 31 | + | |
| 32 | + | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
27 | 36 | | |
28 | 37 | | |
29 | 38 | | |
| 39 | + | |
30 | 40 | | |
31 | 41 | | |
32 | 42 | | |
| |||
110 | 120 | | |
111 | 121 | | |
112 | 122 | | |
113 | | - | |
114 | 123 | | |
115 | 124 | | |
116 | 125 | | |
| |||
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
| 166 | + | |
157 | 167 | | |
158 | 168 | | |
159 | 169 | | |
160 | 170 | | |
161 | 171 | | |
162 | 172 | | |
163 | 173 | | |
164 | | - | |
| 174 | + | |
165 | 175 | | |
166 | 176 | | |
167 | 177 | | |
| |||
311 | 321 | | |
312 | 322 | | |
313 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
314 | 362 | | |
315 | 363 | | |
316 | 364 | | |
| |||
Lines changed: 1 addition & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 87 | + | |
93 | 88 | | |
94 | 89 | | |
95 | 90 | | |
| |||
0 commit comments