Skip to content

Commit

Permalink
Force callers to refresh even when the save fails. (#701)
Browse files Browse the repository at this point in the history
It's possible for the bookmarks store to return an error even when the actual save call succeeded, as Core Data can return errors unrelated to the object you're saving. In this case, the caller will not refresh itself, even despite the data actually having successfully changed under the hood.

This PR updates the failure completion handlers to trigger a refresh regardless. There's more work to do here to track when and how failures happen at all, but this will solve the problem that Alex was seeing.

The issue that Alex is seeing is already repaired when you launch the app, but it's not repaired if an error is encountered at runtime. I'd like to fix that, but want to take more time to do it correctly, so I'll prepare another PR next week – this PR will be enough to get around his issue.
  • Loading branch information
samsymons authored Aug 26, 2022
1 parent 95be7fb commit 6895447
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions DuckDuckGo/Bookmarks/Services/BookmarkStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ final class LocalBookmarkStore: BookmarkStore {
try self.context.save()
} catch {
assertionFailure("LocalBookmarkStore: Saving of context failed")
DispatchQueue.main.async { completion(false, error) }
DispatchQueue.main.async { completion(true, error) }
return
}

Expand Down Expand Up @@ -232,7 +232,7 @@ final class LocalBookmarkStore: BookmarkStore {
try self.context.save()
} catch {
assertionFailure("LocalBookmarkStore: Saving of context failed")
DispatchQueue.main.async { completion(false, error) }
DispatchQueue.main.async { completion(true, error) }
}

DispatchQueue.main.async { completion(true, nil) }
Expand Down Expand Up @@ -405,7 +405,7 @@ final class LocalBookmarkStore: BookmarkStore {
assertionFailure("LocalBookmarkStore: Saving of context failed")
}

DispatchQueue.main.async { completion(false, error) }
DispatchQueue.main.async { completion(true, error) }
return
}

Expand Down

0 comments on commit 6895447

Please sign in to comment.