Skip to content

Commit

Permalink
Added logging for database corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
JaniruTEC committed Jun 2, 2024
1 parent 01a8bd6 commit 7f91090
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,33 @@ private class PatchedCallback(
}

override fun onCorruption(db: SupportSQLiteDatabase) = useFinally({
LOG.e(Exception(), "Called onCorruption for \"${db.path}\"")
//
delegateCallback.onCorruption(db)
//
}, finallyBlock = {
invalidationCallback.invoke()

logCorruptedDbState(db)
})

private fun logCorruptedDbState(db: SupportSQLiteDatabase) {
val state = db.path?.let { path ->
if (path == ":memory:") null else path
}.runCatching {
this?.let { path -> (File(path).exists()) }
}.map {
when (it) {
null -> "In memory"
true -> "Exists"
false -> "Deleted"
}
}.onFailure { verificationFailure ->
LOG.e(verificationFailure, "Couldn't verify state of database \"${db.path}\"")
}.getOrDefault("Unknown (see above)")
LOG.e(Exception(), "State of \"${db.path}\": $state")
}

override fun onOpen(db: SupportSQLiteDatabase) {
//
delegateCallback.onOpen(db)
Expand Down

0 comments on commit 7f91090

Please sign in to comment.