Skip to content

Commit e8d359f

Browse files
authored
Merge pull request #623 from wordpress-mobile/feature/improve-error-logging
Log Aztec details when HTML is not available
2 parents 2908241 + e969875 commit e8d359f

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.wordpress.aztec
22

33
import org.wordpress.android.util.AppLog
4+
import org.wordpress.aztec.util.AztecLog
45
import java.lang.Thread.UncaughtExceptionHandler
56

67
class AztecExceptionHandler(private val logHelper: ExceptionHandlerHelper?, private val visualEditor: AztecText) : UncaughtExceptionHandler {
@@ -31,7 +32,8 @@ class AztecExceptionHandler(private val logHelper: ExceptionHandlerHelper?, priv
3132
try {
3233
AppLog.e(AppLog.T.EDITOR, "HTML Content of Aztec Editor before the crash " + visualEditor.toPlainHtml(false))
3334
} catch (e: Throwable) {
34-
AppLog.e(AppLog.T.EDITOR, "Visual Content of Aztec Editor before the crash " + visualEditor.text)
35+
AppLog.e(AppLog.T.EDITOR, "HTML Content of Aztec Editor before the crash is unavailable, log the details instead")
36+
AztecLog.logEditorContentDetails(visualEditor)
3537
}
3638
}
3739

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,8 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
10471047
output = SpannableStringBuilder(text)
10481048
} catch (e: java.lang.ArrayIndexOutOfBoundsException) {
10491049
// FIXME: Remove this log once we've data to replicate the issue, and fix it in some way.
1050-
AppLog.e(AppLog.T.EDITOR, "There was an error creating SpannableStringBuilder. See #452 for details. " +
1051-
"Following is the text that caused the issue " + text)
1050+
AppLog.e(AppLog.T.EDITOR, "There was an error creating SpannableStringBuilder. See #452 for details.")
1051+
// No need to log the exception here. The ExceptionHandler does this for us.
10521052
throw e
10531053
}
10541054

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
package org.wordpress.aztec.util
22

3+
import org.json.JSONArray
4+
import org.json.JSONException
5+
import org.json.JSONObject
6+
import org.wordpress.android.util.AppLog
7+
import org.wordpress.aztec.AztecText
8+
39
class AztecLog {
410
interface ExternalLogger {
511
fun log(message : String)
612
fun logException(tr : Throwable)
713
fun logException(tr : Throwable, message : String)
814
}
15+
16+
companion object {
17+
fun logEditorContentDetails(aztecText: AztecText) {
18+
try {
19+
val logContentJSON = JSONObject()
20+
logContentJSON.put("content", aztecText.text.toString())
21+
logContentJSON.put("length", aztecText.text.length)
22+
val spansJSON = JSONArray()
23+
val spans = aztecText.text.getSpans(0, aztecText.text.length, Any::class.java)
24+
spans.forEach {
25+
val currenSpanJSON = JSONObject()
26+
currenSpanJSON.put("clasz", it.javaClass.name)
27+
currenSpanJSON.put("start", aztecText.text.getSpanStart(it))
28+
currenSpanJSON.put("end", aztecText.text.getSpanEnd(it))
29+
currenSpanJSON.put("flags", aztecText.text.getSpanFlags(it))
30+
spansJSON.put(currenSpanJSON)
31+
}
32+
logContentJSON.put("spans", spansJSON)
33+
AppLog.d(AppLog.T.EDITOR, "Below are the details of the content in the editor:")
34+
AppLog.d(AppLog.T.EDITOR, logContentJSON.toString())
35+
} catch (e: JSONException) {
36+
AppLog.e(AppLog.T.EDITOR, "Uhh ohh! There was an error logging the content of the Editor. This should" +
37+
"never happen.", e)
38+
}
39+
}
40+
}
941
}

0 commit comments

Comments
 (0)