Skip to content

Commit 539f208

Browse files
committed
Log the errors, and the internal state, but don't shallow the original exceptions.
1 parent e7e3a18 commit 539f208

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,29 @@ import org.xml.sax.helpers.AttributesImpl
77
class AztecAttributes(attributes: Attributes = AttributesImpl()) : AttributesImpl(attributes) {
88
fun setValue(key: String, value: String) {
99
val index = getIndex(key)
10+
1011
if (index == -1) {
11-
addAttribute("", key, key, "string", value)
12-
} else {
1312
try {
14-
setValue(index, value)
13+
addAttribute("", key, key, "string", value)
1514
} catch (e: ArrayIndexOutOfBoundsException) {
16-
// we should not be here since `getIndex(key)` checks if the attribute is already available or not,
17-
// but apparently...https://github.com/wordpress-mobile/AztecEditor-Android/issues/705
18-
AppLog.e(AppLog.T.EDITOR, "Tried to set attribute: $key at index: $index")
15+
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/705
16+
AppLog.e(AppLog.T.EDITOR, "Error adding attribute with name: $key and value: $value")
17+
logInternalState()
18+
throw e
1919
}
20+
} else {
21+
setValue(index, value)
22+
}
23+
}
24+
25+
private fun logInternalState() {
26+
AppLog.e(AppLog.T.EDITOR, "AttributesImpl has an internal length of $length")
27+
// Since we're not sure the internal state of the Obj is correct we're wrapping toString in a try/catch
28+
try {
29+
AppLog.e(AppLog.T.EDITOR, "Dumping internal state:")
30+
AppLog.e(AppLog.T.EDITOR, toString())
31+
} catch (t: Throwable) {
32+
AppLog.e(AppLog.T.EDITOR, "Error dumping internal state!")
2033
}
2134
}
2235

@@ -30,10 +43,11 @@ class AztecAttributes(attributes: Attributes = AttributesImpl()) : AttributesImp
3043
try {
3144
removeAttribute(index)
3245
} catch (e: ArrayIndexOutOfBoundsException) {
33-
// we should not be here since hasAttribute checked if the attribute is available or not,
34-
// but apparently...https://github.com/wordpress-mobile/AztecEditor-Android/issues/705
35-
AppLog.e(AppLog.T.EDITOR, "Tried to remove attribute: $key that is not in the list.")
46+
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/705
47+
AppLog.e(AppLog.T.EDITOR, "Tried to remove attribute: $key that is not in the list")
3648
AppLog.e(AppLog.T.EDITOR, "Reported to be at index: $index")
49+
logInternalState()
50+
throw e
3751
}
3852
}
3953
}

0 commit comments

Comments
 (0)