-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Catch and log exceptions (#64)
* feat: Add rudimentary error boundary Catch render errors with Gutenberg's default error boundary component. * feat: Log render errors to the host app Allow the host app to act on errors. * feat: Log error details to iOS host app Allow the iOS host app to act on errors. * feat: Parse errors Extract relevant attributes for logging to monitoring services. * refactor: Hoist error boundary into layout component Catch errors within the editor component. * build: Add Gson Enable parsing stringified JSON objects sent from WebViews to the host Android app. * feat: Add logic for logging exceptions to Android host Enable the Android host app to act upon editor exceptions. * task: Capture build output * refactor: Improve editor exception type safety * refactor: Rename "error" to "exception" The latter better describes these "handled" errors.
- Loading branch information
Showing
27 changed files
with
1,328 additions
and
830 deletions.
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
66 changes: 66 additions & 0 deletions
66
android/Gutenberg/src/main/java/org/wordpress/gutenberg/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,66 @@ | ||
package org.wordpress.gutenberg | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.JsonObject | ||
|
||
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 fromString(exceptionString: String): GutenbergJsException { | ||
val gson = Gson() | ||
val rawException = gson.fromJson(exceptionString, JsonObject::class.java) | ||
|
||
val type = rawException.get("type")?.asString ?: "" | ||
val message = rawException.get("message")?.asString ?: "" | ||
|
||
val stackTrace = rawException.getAsJsonArray("stacktrace")?.map { element -> | ||
val stackTraceElement = element.asJsonObject | ||
val stackTraceFunction = stackTraceElement.get("function")?.asString | ||
stackTraceFunction?.let { | ||
JsExceptionStackTraceElement( | ||
stackTraceElement.get("filename")?.asString, | ||
stackTraceElement.get("lineno")?.asInt, | ||
stackTraceElement.get("colno")?.asInt, | ||
stackTraceFunction | ||
) | ||
} | ||
}?.filterNotNull() ?: emptyList() | ||
|
||
val context = rawException.getAsJsonObject("context")?.entrySet()?.associate { | ||
it.key to it.value.asString | ||
} ?: emptyMap() | ||
|
||
val tags = rawException.getAsJsonObject("tags")?.entrySet()?.associate { | ||
it.key to it.value.asString | ||
} ?: emptyMap() | ||
|
||
val isHandled = rawException.get("isHandled")?.asBoolean ?: false | ||
val handledBy = rawException.get("handledBy")?.asString ?: "" | ||
|
||
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
830 changes: 830 additions & 0 deletions
830
ios/Sources/GutenbergKit/Gutenberg/assets/index-CVihFZVi.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...rgKit/Gutenberg/assets/index-CTMt5Mdc.css → ...rgKit/Gutenberg/assets/index-HX5OH3UO.css
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.