Fix some minor bugs
- Observe profiles on Simulator - Dismiss on error when fetching migratable profiles - Improve migration logs ambiguity
This commit is contained in:
parent
c93a43702c
commit
01e0559060
|
@ -149,8 +149,9 @@ private extension MigrateView {
|
|||
model.step = .fetched(model.profiles)
|
||||
} catch {
|
||||
pp_log(.App.migration, .error, "Unable to fetch migratable profiles: \(error)")
|
||||
errorHandler.handle(error, title: title)
|
||||
model.step = .initial
|
||||
errorHandler.handle(error, title: title) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ final class CDProfileRepositoryV2: Sendable {
|
|||
map: {
|
||||
$0.compactMap {
|
||||
guard $0.value.encryptedJSON ?? $0.value.json != nil else {
|
||||
pp_log(.App.migration, .error, "Unable to migrate profile \($0.key): missing JSON")
|
||||
pp_log(.App.migration, .error, "ProfileV2 \($0.key) is not migratable: missing JSON")
|
||||
return nil
|
||||
}
|
||||
return MigratableProfile(
|
||||
|
@ -78,13 +78,13 @@ final class CDProfileRepositoryV2: Sendable {
|
|||
map: {
|
||||
$0.compactMap {
|
||||
guard let json = $0.value.encryptedJSON ?? $0.value.json else {
|
||||
pp_log(.App.migration, .error, "Unable to migrate profile \($0.key): missing JSON")
|
||||
pp_log(.App.migration, .error, "ProfileV2 \($0.key) is not migratable: missing JSON")
|
||||
return nil
|
||||
}
|
||||
do {
|
||||
return try decoder.decode(ProfileV2.self, from: json)
|
||||
} catch {
|
||||
pp_log(.App.migration, .error, "Unable to migrate profile \($0.key): \(error)")
|
||||
pp_log(.App.migration, .error, "Unable to decode ProfileV2 \($0.key): \(error)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ final class CDProfileRepositoryV2: Sendable {
|
|||
return
|
||||
}
|
||||
let request = CDProfile.fetchRequest()
|
||||
request.predicate = NSPredicate(format: "any uuid in %@", profileIds.map(\.uuidString))
|
||||
request.predicate = NSPredicate(format: "any uuid in %@", profileIds)
|
||||
let existing = try context.fetch(request)
|
||||
existing.forEach(context.delete)
|
||||
try context.save()
|
||||
|
@ -130,7 +130,7 @@ extension CDProfileRepositoryV2 {
|
|||
return
|
||||
}
|
||||
guard !deduped.keys.contains(uuid) else {
|
||||
pp_log(.App.migration, .info, "Skip older duplicate of profile \(uuid)")
|
||||
pp_log(.App.migration, .info, "Skip older duplicate of ProfileV2 \(uuid)")
|
||||
return
|
||||
}
|
||||
deduped[uuid] = $0
|
||||
|
|
|
@ -67,7 +67,7 @@ extension ProfileV2MigrationStrategy {
|
|||
}
|
||||
return try mapper.toProfileV3(profile)
|
||||
} catch {
|
||||
pp_log(.App.migration, .error, "Unable to migrate profile \(profileId): \(error)")
|
||||
pp_log(.App.migration, .error, "Unable to fetch and map migratable profile \(profileId): \(error)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ private extension Configuration {
|
|||
@MainActor
|
||||
private extension Configuration.ProfileManager {
|
||||
static var mainProfileRepository: ProfileRepository {
|
||||
coreDataProfileRepository
|
||||
coreDataProfileRepository(observingResults: true)
|
||||
}
|
||||
|
||||
static var backupProfileRepository: ProfileRepository? {
|
||||
|
@ -161,7 +161,7 @@ private extension Configuration.ProfileManager {
|
|||
}
|
||||
|
||||
static var backupProfileRepository: ProfileRepository? {
|
||||
coreDataProfileRepository
|
||||
coreDataProfileRepository(observingResults: false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ private extension Configuration.ProfileManager {
|
|||
)
|
||||
}()
|
||||
|
||||
static let coreDataProfileRepository: ProfileRepository = {
|
||||
static func coreDataProfileRepository(observingResults: Bool) -> ProfileRepository {
|
||||
let store = CoreDataPersistentStore(
|
||||
logger: .default,
|
||||
containerName: Constants.shared.containers.local,
|
||||
|
@ -204,12 +204,12 @@ private extension Configuration.ProfileManager {
|
|||
registry: .shared,
|
||||
coder: CodableProfileCoder(),
|
||||
context: store.context,
|
||||
observingResults: false
|
||||
observingResults: observingResults
|
||||
) { error in
|
||||
pp_log(.app, .error, "Unable to decode local result: \(error)")
|
||||
return .ignore
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Logging
|
||||
|
|
Loading…
Reference in New Issue