-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[RNMobile] Add error boundry handling for Android #59385
Merged
fluiddot
merged 11 commits into
rnmobile/add/error-boundary
from
rnmobile/update/error-boundary/android
Mar 7, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
48e7fe2
Add logException to Android bridge
jhnstn 41f8c1f
Add logException to Android demo app
jhnstn 38518a7
Add GutenbergJsException data class
jhnstn 8755437
Update logException to use data class and return bool to callback
jhnstn b61200e
integrate exception handling in the glue code
jhnstn b956669
remove past tense 'did'
jhnstn 050de88
Refactor exception processing
jhnstn 7664490
Merge branch 'rnmobile/add/error-boundary' into rnmobile/update/error…
jhnstn 96f53be
lint
jhnstn f3211da
Add `logException` bridge function in demo app
fluiddot d8c72e1
Update stacktrace parsing on Android
fluiddot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,13 @@ | |
import com.facebook.react.modules.core.DeviceEventManagerModule; | ||
|
||
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.ConnectionStatusCallback; | ||
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.LogExceptionCallback; | ||
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaType; | ||
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.OtherMediaOptionsReceivedCallback; | ||
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.FocalPointPickerTooltipShownCallback; | ||
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.BlockTypeImpressionsCallback; | ||
import org.wordpress.mobile.WPAndroidGlue.DeferredEventEmitter; | ||
import org.wordpress.mobile.WPAndroidGlue.GutenbergJsException; | ||
import org.wordpress.mobile.WPAndroidGlue.MediaOption; | ||
|
||
import java.io.Serializable; | ||
|
@@ -593,4 +595,19 @@ public void hideAndroidSoftKeyboard() { | |
} | ||
} | ||
} | ||
|
||
@ReactMethod | ||
public void logException(final ReadableMap rawException, final Callback jsCallback) { | ||
GutenbergJsException exception = GutenbergJsException.fromReadableMap(rawException); | ||
LogExceptionCallback logExceptionCallback = onLogExceptionCallback(jsCallback); | ||
mGutenbergBridgeJS2Parent.logException(exception, logExceptionCallback); | ||
} | ||
|
||
private LogExceptionCallback onLogExceptionCallback(final Callback jsCallback) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm following the same encapsulation used for other callbacks in the bridge, such as |
||
return new GutenbergBridgeJS2Parent.LogExceptionCallback() { | ||
@Override public void onLogException(boolean success) { | ||
jsCallback.invoke(success); | ||
} | ||
}; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ct-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergJsException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.wordpress.mobile.WPAndroidGlue | ||
|
||
import com.facebook.react.bridge.ReadableMap | ||
|
||
data class JsExceptionStackTraceElement ( | ||
val fileName: String?, | ||
val lineNumber: Int?, | ||
val colNumber: Int?, | ||
val function: String, | ||
) | ||
class GutenbergJsException ( | ||
val type: String, | ||
val message: String, | ||
var stackTrace: List<JsExceptionStackTraceElement>, | ||
val context: Map<String, Any> = emptyMap(), | ||
val tags: Map<String,String> = emptyMap(), | ||
val isHandled: Boolean, | ||
val handledBy: String | ||
) { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun fromReadableMap(rawException: ReadableMap): GutenbergJsException { | ||
val type: String = rawException.getString("type") ?: "" | ||
val message: String = rawException.getString("message") ?: "" | ||
|
||
val stackTrace: List<JsExceptionStackTraceElement> = rawException.getArray("stacktrace")?.let { | ||
(0 until it.size()).mapNotNull { index -> | ||
val stackTraceElement = it.getMap(index) | ||
stackTraceElement?.let { | ||
val stackTraceFunction = stackTraceElement.getString("function") | ||
stackTraceFunction?.let { | ||
JsExceptionStackTraceElement( | ||
stackTraceElement.getString("filename"), | ||
if (stackTraceElement.hasKey("lineno")) stackTraceElement.getInt("lineno") else null, | ||
if (stackTraceElement.hasKey("colno")) stackTraceElement.getInt("colno") else null, | ||
stackTraceFunction | ||
) | ||
} | ||
} | ||
} | ||
} ?: emptyList() | ||
|
||
val context: Map<String, Any> = rawException.getMap("context")?.toHashMap() ?: emptyMap() | ||
val tags: Map<String, String> = rawException.getMap("tags")?.toHashMap()?.mapValues { it.value.toString() } ?: emptyMap() | ||
val isHandled: Boolean = rawException.getBoolean("isHandled") | ||
val handledBy: String = rawException.getString("handledBy") ?: "" | ||
|
||
return GutenbergJsException( | ||
type, | ||
message, | ||
stackTrace, | ||
context, | ||
tags, | ||
isHandled, | ||
handledBy | ||
) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe Android Studio removed this when it linted the file.