From b85230b0ff23cc246e444a3c54075b8f1468ae0f Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 12 Jun 2020 13:00:18 -0700 Subject: [PATCH] =?UTF-8?q?Improves=20sync=20error=20messages=20when=20a?= =?UTF-8?q?=20game=20is=20missing=20or=20can=E2=80=99t=20be=20synced?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Delta/Syncing/SyncResultViewController.swift | 40 +++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/Delta/Syncing/SyncResultViewController.swift b/Delta/Syncing/SyncResultViewController.swift index 4de8bf6..cff2758 100644 --- a/Delta/Syncing/SyncResultViewController.swift +++ b/Delta/Syncing/SyncResultViewController.swift @@ -163,6 +163,16 @@ private extension SyncResultViewController errorMessage = messages.joined(separator: "\n") } + case .other(_, ValidationError.nilRelationshipObjects(let relationships)) where relationships.contains("game"): + if let gameName = error.record.localMetadata?[.gameName] ?? error.record.remoteMetadata?[.gameName] + { + errorMessage = String(format: NSLocalizedString("“%@“ is missing. Please re-import this game to resume syncing its data.", comment: ""), gameName) + } + else + { + errorMessage = NSLocalizedString("The game for this item is missing. Please re-import the game to resume syncing its data.", comment: "") + } + case .other(_, let error as NSError): errorMessage = error.localizedFailureReason ?? error.localizedDescription default: errorMessage = error.failureReason } @@ -265,12 +275,38 @@ private extension SyncResultViewController for (group, errors) in errorsByGroup { - let sortedErrors = errors.sorted { (a, b) -> Bool in + let filteredErrors = errors.filter { error in + switch group + { + case .saveState(let gameID), .cheat(let gameID): + switch error + { + case RecordError.other(_, ValidationError.nilRelationshipObjects(let relationships)) where relationships.contains("game"): + if errorsByGroup.keys.contains(Group.game(gameID)) + { + // There is already an error for this game, so don't need to duplicate it due to it missing. + return false + } + else + { + return true + } + + default: break + } + + default: break + } + + return true + } + + let sortedErrors = filteredErrors.sorted { (a, b) -> Bool in guard let a = a as? RecordError, let b = b as? RecordError else { return false } return a.record.localizedTitle < b.record.localizedTitle } - errorsByGroup[group] = sortedErrors + errorsByGroup[group] = sortedErrors.isEmpty ? nil : sortedErrors } let sortedErrors = errorsByGroup.sorted { (a, b) in