Skip to content

Commit

Permalink
[core] Delete cache file if exception occurred while loading GroupMem…
Browse files Browse the repository at this point in the history
…berListCache. Fix #2399
  • Loading branch information
Him188 committed Jan 2, 2023
1 parent 62ae2ac commit eea2ef5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mirai-core/src/commonMain/kotlin/network/ContactListCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ internal class GroupMemberListCaches(
return map.getOrPut(id) {
val file = resolveCacheFile(id)
if (file.exists() && file.isFile) {
val text = file.readText()
if (text.isNotBlank()) {
return JsonForCache.decodeFromString(GroupMemberListCache.serializer(), text)
try {
val text = file.readText()
if (text.isNotBlank()) {
return JsonForCache.decodeFromString(GroupMemberListCache.serializer(), text)
}
} catch (e: Exception) {
logger.warning(
"Exception while loading GroupMemberListCache for group $id, possibly file corrupted. Deleting cache file.",
e
)
file.delete()
}
}

Expand Down

0 comments on commit eea2ef5

Please sign in to comment.