[core] Delete cache file if exception occurred while loading GroupMemberListCache. Fix #2399

This commit is contained in:
Him188 2022-12-17 21:28:30 +00:00
parent 62ae2ac03c
commit eea2ef509d
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375

View File

@ -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()
}
}