Skip to content

fix(backup): declare restore failures for Swift callers - #2

Merged
AritxOnly merged 1 commit into
DeadlinerStudio:byosfrom
Tequilaar:mac/backup-restore-throws
Nov 3, 2026
Merged

AritxOnly merged 1 commit into
DeadlinerStudio:byosfrom
Tequilaar:mac/backup-restore-throws

Conversation

@Tequilaar

Copy link
Copy Markdown

改动

BackupService.restore(raw:) 加上 @Throws(IllegalArgumentException::class)(另加一行注释),共 2 行。

原因

restore 遇到无效文件时抛出 IllegalArgumentException:JSON 解码失败(SerializationException)、require() 检查(备份格式版本、V5 习惯专注、对话记录)和 SnapshotV3ValidationException 都是它的子类。Kotlin/Native 中没有声明 @Throws 的异常传到 Swift 会直接终止进程,所以 Apple 端选错一个文件就会让应用退出,而且 Swift 无法事先完整检查(SnapshotV3Codec.decode 同样会抛出)。

加上之后,Swift 侧为 restore(raw:) throws,可以给出错误提示;替换在一个事务中完成,失败时本机数据不变。

影响

  • Kotlin 调用方(Android 等)不受影响。
  • Apple 头文件只有这一个方法变化:- (BOOL)restoreRaw:error:,Swift 中调用需加 try。目前 iOS 仓库没有调用 restore。

验证

  • ./gradlew -PlifiMode=stub :shared:macosArm64Test:274 个测试全部通过。
  • Mac 客户端的导入测试:正常备份可以导入;三种无效文件(错误的备份格式版本、快照中有未知字段、快照格式版本过旧)都得到错误,数据不变,应用不退出。

BackupService.restore rejects invalid files with IllegalArgumentException
(kotlinx.serialization's SerializationException, require() checks and
SnapshotV3ValidationException all extend it). Without @throws the
exception aborts the process on Apple targets; with it Swift gets
restore(raw:) throws and can show an error instead.

@AritxOnly AritxOnly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Swift exception declaration and restore validation paths.

Validation: combined PR #1–#4 checkout with both follow-up fixes; ./gradlew --offline -PlifiMode=stub :shared:macosArm64Test — 280 tests passed, 0 failures. Private Lifi mode and iOS framework linking were not rerun in this pass.

@AritxOnly
AritxOnly merged commit c5f1dfd into DeadlinerStudio:byos Nov 3, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants