Repository navigation
fix(backup): declare restore failures for Swift callers - #2
Merged
AritxOnly merged 1 commit intoNov 3, 2026
Merged
Conversation
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
approved these changes
Nov 3, 2026
AritxOnly
left a comment
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动
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,可以给出错误提示;替换在一个事务中完成,失败时本机数据不变。影响
- (BOOL)restoreRaw:error:,Swift 中调用需加try。目前 iOS 仓库没有调用restore。验证
./gradlew -PlifiMode=stub :shared:macosArm64Test:274 个测试全部通过。