From 5bb86cf84fa617088b6cdc4e3165295dd8c215b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=80=A1=E7=84=B6?= <63996691+zhaodice@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:58:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20=E7=BC=93=E5=AD=98=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=9B=A0=E4=B8=BA=E8=AE=A1=E7=AE=97=E6=9C=BA=E7=A1=AC=E7=A2=9F?= =?UTF-8?q?=E6=88=96=E7=A8=8B=E5=BC=8F=E4=B8=8D=E7=A8=B3=E5=AE=9A=E9=80=A0?= =?UTF-8?q?=E6=88=90=E6=8D=9F=E6=AF=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/commonMain/kotlin/Serialization.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt index 72294bc254..0e7d2b8e5a 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 + } } - From e6a953e05f08534aaa2198c1a70e8ba43d477f2f Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 3 Mar 2024 00:00:49 +0000 Subject: [PATCH 2/2] Apply suggestions from code review --- mirai-core-utils/src/commonMain/kotlin/Serialization.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt index 0e7d2b8e5a..37f79fa474 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt @@ -72,9 +72,9 @@ public fun MiraiFile.loadNotBlankAs( if (!this.exists() || this.length == 0L) { return null } - return try{ + return try { stringFormat.decodeFromString(serializer, this.readText()) - }catch(e:Throwable){//broken file + } catch (e: Throwable) { //broken file e.printStackTrace() null } @@ -87,9 +87,9 @@ public fun MiraiFile.loadNotBlankAs( if (!this.exists() || this.length == 0L) { return null } - return try{ + return try { binaryFormat.decodeFromByteArray(serializer, this.readBytes()) - }catch(e:Throwable){//broken file + } catch (e: Throwable) { //broken file e.printStackTrace() null }