diff --git a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt index 72294bc254..37f79fa474 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt @@ -72,7 +72,12 @@ public fun MiraiFile.loadNotBlankAs( if (!this.exists() || this.length == 0L) { return null } - return stringFormat.decodeFromString(serializer, this.readText()) + return try { + stringFormat.decodeFromString(serializer, this.readText()) + } catch (e: Throwable) { //broken file + e.printStackTrace() + null + } } public fun MiraiFile.loadNotBlankAs( @@ -82,6 +87,10 @@ public fun MiraiFile.loadNotBlankAs( if (!this.exists() || this.length == 0L) { return null } - return binaryFormat.decodeFromByteArray(serializer, this.readBytes()) + return try { + binaryFormat.decodeFromByteArray(serializer, this.readBytes()) + } catch (e: Throwable) { //broken file + e.printStackTrace() + null + } } -