mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 10:47:21 +00:00
Fix bug where a database-suspended fetch error could leave timeline empty with the only recourse a quit-and-relaunch. Fixes #5257.
This commit is contained in:
1 parent
cd3c6d0173
commit
04fe9f0ff7
1 file changed
+55
-14
@@ -7,9 +7,12 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os
|
||||
import RSCore
|
||||
import RSDatabase
|
||||
import Account
|
||||
import Articles
|
||||
import ErrorLog
|
||||
|
||||
// Main thread only.
|
||||
// Runs an asynchronous fetch.
|
||||
@@ -65,6 +68,8 @@ typealias FetchRequestOperationResultBlock = (Set<Article>, FetchRequestOperatio
|
||||
return
|
||||
}
|
||||
|
||||
Self.logger.debug("FetchRequestOperation \(self.id, privacy: .public): run starting — \(self.fetchers.count) fetcher(s)")
|
||||
|
||||
let numberOfFetchers = fetchers.count
|
||||
var fetchersReturned = 0
|
||||
var fetchedArticles = Set<Article>()
|
||||
@@ -88,16 +93,24 @@ typealias FetchRequestOperationResultBlock = (Set<Article>, FetchRequestOperatio
|
||||
}
|
||||
|
||||
for fetcher in fetchers {
|
||||
if (fetcher as? SidebarItem)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true {
|
||||
if let articles = try? await fetcher.fetchUnreadArticlesAsync() {
|
||||
process(articles)
|
||||
}
|
||||
} else {
|
||||
if let articles = try? await fetcher.fetchArticlesAsync() {
|
||||
process(articles)
|
||||
let articles: Set<Article>
|
||||
do {
|
||||
if (fetcher as? SidebarItem)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true {
|
||||
articles = try await fetcher.fetchUnreadArticlesAsync()
|
||||
} else {
|
||||
articles = try await fetcher.fetchArticlesAsync()
|
||||
}
|
||||
} catch {
|
||||
Self.logger.error("FetchRequestOperation \(self.id, privacy: .public): fetcher threw — \(String(describing: error), privacy: .public)")
|
||||
Self.postFetchError(error)
|
||||
articles = []
|
||||
}
|
||||
process(articles)
|
||||
}
|
||||
|
||||
// Belt-and-suspenders: ensure the queue never deadlocks even if
|
||||
// the loop above is ever refactored to skip process().
|
||||
callCompletionIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +160,8 @@ typealias FetchRequestOperationResultBlock = (Set<Article>, FetchRequestOperatio
|
||||
return
|
||||
}
|
||||
|
||||
Self.logger.debug("FetchRequestOperation \(self.id, privacy: .public): run starting — \(self.fetchers.count) fetcher(s)")
|
||||
|
||||
let numberOfFetchers = fetchers.count
|
||||
var fetchersReturned = 0
|
||||
var fetchedArticles = Set<Article>()
|
||||
@@ -177,18 +192,44 @@ typealias FetchRequestOperationResultBlock = (Set<Article>, FetchRequestOperatio
|
||||
}
|
||||
|
||||
for fetcher in fetchers {
|
||||
if fetcherHidesReadArticles(fetcher) {
|
||||
if let articles = try? await fetcher.fetchUnreadArticlesAsync() {
|
||||
process(articles)
|
||||
}
|
||||
} else {
|
||||
if let articles = try? await fetcher.fetchArticlesAsync() {
|
||||
process(articles)
|
||||
let articles: Set<Article>
|
||||
do {
|
||||
if fetcherHidesReadArticles(fetcher) {
|
||||
articles = try await fetcher.fetchUnreadArticlesAsync()
|
||||
} else {
|
||||
articles = try await fetcher.fetchArticlesAsync()
|
||||
}
|
||||
} catch {
|
||||
Self.logger.error("FetchRequestOperation \(self.id, privacy: .public): fetcher threw — \(String(describing: error), privacy: .public)")
|
||||
Self.postFetchError(error)
|
||||
articles = []
|
||||
}
|
||||
process(articles)
|
||||
}
|
||||
|
||||
// Ensure the queue never deadlocks even if
|
||||
// the loop above is ever refactored to skip process().
|
||||
callCompletionIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private extension FetchRequestOperation {
|
||||
|
||||
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FetchRequestOperation")
|
||||
static let errorLogSourceID = 101
|
||||
|
||||
static func postFetchError(_ error: Error, fileName: String = #fileID, functionName: String = #function, lineNumber: Int = #line) {
|
||||
let typeName = String(describing: type(of: error))
|
||||
let description: String
|
||||
if let databaseError = error as? DatabaseError {
|
||||
description = "\(typeName).\(databaseError): \(error.localizedDescription)"
|
||||
} else {
|
||||
description = "\(typeName): \(error.localizedDescription)"
|
||||
}
|
||||
let userInfo = ErrorLogUserInfoKey.userInfo(sourceName: "Timeline", sourceID: errorLogSourceID, operation: "Fetching articles", errorMessage: description, fileName: fileName, functionName: functionName, lineNumber: lineNumber)
|
||||
NotificationCenter.default.post(name: .appDidEncounterError, object: nil, userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user