-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 5 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
49 changes: 49 additions & 0 deletions
49
...dge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/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,49 @@ | ||
package org.wordpress.mobile.ReactNativeGutenbergBridge | ||
|
||
import com.facebook.react.bridge.ReadableMap | ||
|
||
data class GutenbergJsException( | ||
var type: String, | ||
var value: String, | ||
jhnstn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var stackTrace: List<GutenbergJsExceptionStackTraceElement>, | ||
var context: Map<String, Any> = emptyMap(), | ||
var tags: Map<String,String> = emptyMap(), | ||
var isHandled: Boolean, | ||
var handledBy: String | ||
){ | ||
companion object { | ||
@JvmStatic | ||
fun fromReadableMap(rawException: ReadableMap): GutenbergJsException { | ||
val type: String = rawException.getString("type") ?: "" | ||
val value: String = rawException.getString("value") ?: "" | ||
val stackTrace: List<GutenbergJsExceptionStackTraceElement> = rawException.getArray("stackTrace")?.toArrayList()?.map { | ||
val stackTraceElement = it as ReadableMap | ||
GutenbergJsExceptionStackTraceElement( | ||
stackTraceElement.getString("fileName") ?: "", | ||
jhnstn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stackTraceElement.getInt("lineNumber"), | ||
jhnstn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stackTraceElement.getString("function") ?: "" | ||
) | ||
} ?: 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, | ||
value, | ||
stackTrace, | ||
context, | ||
tags, | ||
isHandled, | ||
handledBy | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class GutenbergJsExceptionStackTraceElement( | ||
var fileName: String, | ||
var lineNumber: Int, | ||
var function: String | ||
) | ||
jhnstn marked this conversation as resolved.
Show resolved
Hide resolved
|
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,6 +28,7 @@ | |
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; | ||
|
@@ -623,4 +624,20 @@ 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); | ||
} | ||
}; | ||
} | ||
} |
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.