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)
|
model.step = .fetched(model.profiles)
|
||||||
} catch {
|
} catch {
|
||||||
pp_log(.App.migration, .error, "Unable to fetch migratable profiles: \(error)")
|
pp_log(.App.migration, .error, "Unable to fetch migratable profiles: \(error)")
|
||||||
errorHandler.handle(error, title: title)
|
errorHandler.handle(error, title: title) {
|
||||||
model.step = .initial
|
dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ final class CDProfileRepositoryV2: Sendable {
|
||||||
map: {
|
map: {
|
||||||
$0.compactMap {
|
$0.compactMap {
|
||||||
guard $0.value.encryptedJSON ?? $0.value.json != nil else {
|
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 nil
|
||||||
}
|
}
|
||||||
return MigratableProfile(
|
return MigratableProfile(
|
||||||
|
@ -78,13 +78,13 @@ final class CDProfileRepositoryV2: Sendable {
|
||||||
map: {
|
map: {
|
||||||
$0.compactMap {
|
$0.compactMap {
|
||||||
guard let json = $0.value.encryptedJSON ?? $0.value.json else {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
return try decoder.decode(ProfileV2.self, from: json)
|
return try decoder.decode(ProfileV2.self, from: json)
|
||||||
} catch {
|
} 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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ final class CDProfileRepositoryV2: Sendable {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let request = CDProfile.fetchRequest()
|
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)
|
let existing = try context.fetch(request)
|
||||||
existing.forEach(context.delete)
|
existing.forEach(context.delete)
|
||||||
try context.save()
|
try context.save()
|
||||||
|
@ -130,7 +130,7 @@ extension CDProfileRepositoryV2 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard !deduped.keys.contains(uuid) else {
|
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
|
return
|
||||||
}
|
}
|
||||||
deduped[uuid] = $0
|
deduped[uuid] = $0
|
||||||
|
|
|
@ -67,7 +67,7 @@ extension ProfileV2MigrationStrategy {
|
||||||
}
|
}
|
||||||
return try mapper.toProfileV3(profile)
|
return try mapper.toProfileV3(profile)
|
||||||
} catch {
|
} 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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ private extension Configuration {
|
||||||
@MainActor
|
@MainActor
|
||||||
private extension Configuration.ProfileManager {
|
private extension Configuration.ProfileManager {
|
||||||
static var mainProfileRepository: ProfileRepository {
|
static var mainProfileRepository: ProfileRepository {
|
||||||
coreDataProfileRepository
|
coreDataProfileRepository(observingResults: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
static var backupProfileRepository: ProfileRepository? {
|
static var backupProfileRepository: ProfileRepository? {
|
||||||
|
@ -161,7 +161,7 @@ private extension Configuration.ProfileManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static var backupProfileRepository: ProfileRepository? {
|
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(
|
let store = CoreDataPersistentStore(
|
||||||
logger: .default,
|
logger: .default,
|
||||||
containerName: Constants.shared.containers.local,
|
containerName: Constants.shared.containers.local,
|
||||||
|
@ -204,12 +204,12 @@ private extension Configuration.ProfileManager {
|
||||||
registry: .shared,
|
registry: .shared,
|
||||||
coder: CodableProfileCoder(),
|
coder: CodableProfileCoder(),
|
||||||
context: store.context,
|
context: store.context,
|
||||||
observingResults: false
|
observingResults: observingResults
|
||||||
) { error in
|
) { error in
|
||||||
pp_log(.app, .error, "Unable to decode local result: \(error)")
|
pp_log(.app, .error, "Unable to decode local result: \(error)")
|
||||||
return .ignore
|
return .ignore
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Logging
|
// MARK: - Logging
|
||||||
|
|
Loading…
Reference in New Issue