mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 18:32:55 +00:00
Add operation column that says what the app was actually doing.
This commit is contained in:
1 parent
21907eef6e
commit
3587b5eba0
6 files changed
+39
-25
No files matched your search
+16
-12
@@ -265,6 +265,10 @@ let appName = "NetNewsWire"
|
||||
CrashReporter.check(crashReporter: crashReporter)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
postFakeErrorsForTesting()
|
||||
#endif
|
||||
}
|
||||
|
||||
func application(_ application: NSApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool {
|
||||
@@ -701,20 +705,20 @@ extension AppDelegate {
|
||||
|
||||
#if DEBUG
|
||||
func postFakeErrorsForTesting() {
|
||||
let fakeErrors: [(String, Int, String)] = [
|
||||
("On My Mac", AccountType.onMyMac.rawValue, "HTTP 404 Not Found: https://example.com/feed.xml"),
|
||||
("Feedbin", AccountType.feedbin.rawValue, "HTTP 401 Unauthorized"),
|
||||
("iCloud", AccountType.cloudKit.rawValue, "HTTP 429 Too Many Requests: https://daringfireball.net/feeds/main"),
|
||||
("NewsBlur", AccountType.newsBlur.rawValue, "The operation couldn\u{2019}t be completed. Network connection lost."),
|
||||
("FreshRSS", AccountType.freshRSS.rawValue, "HTTP 403 Forbidden: https://freshrss.example.com/api/greader.php"),
|
||||
("Feedly", AccountType.feedly.rawValue, "HTTP 500 Internal Server Error: https://cloud.feedly.com/v3/streams"),
|
||||
("Inoreader", AccountType.inoreader.rawValue, "The request timed out."),
|
||||
("BazQux", AccountType.bazQux.rawValue, "HTTP 502 Bad Gateway: https://www.bazqux.com/reader/api"),
|
||||
("The Old Reader", AccountType.theOldReader.rawValue, "A server with the specified hostname could not be found.")
|
||||
let fakeErrors: [(String, Int, String, String)] = [
|
||||
("On My Mac", AccountType.onMyMac.rawValue, "Downloading feed", "HTTP 404 Not Found: https://example.com/feed.xml"),
|
||||
("Feedbin", AccountType.feedbin.rawValue, "Syncing starred status", "HTTP 401 Unauthorized"),
|
||||
("iCloud", AccountType.cloudKit.rawValue, "Refreshing", "HTTP 429 Too Many Requests: https://daringfireball.net/feeds/main"),
|
||||
("NewsBlur", AccountType.newsBlur.rawValue, "Syncing read status", "The operation couldn\u{2019}t be completed. Network connection lost."),
|
||||
("FreshRSS", AccountType.freshRSS.rawValue, "Refreshing articles", "HTTP 403 Forbidden: https://freshrss.example.com/api/greader.php"),
|
||||
("Feedly", AccountType.feedly.rawValue, "Restoring feed", "HTTP 500 Internal Server Error: https://cloud.feedly.com/v3/streams"),
|
||||
("Inoreader", AccountType.inoreader.rawValue, "Refreshing", "The request timed out."),
|
||||
("BazQux", AccountType.bazQux.rawValue, "Removing feed", "HTTP 502 Bad Gateway: https://www.bazqux.com/reader/api"),
|
||||
("The Old Reader", AccountType.theOldReader.rawValue, "Refreshing articles", "A server with the specified hostname could not be found.")
|
||||
]
|
||||
|
||||
for (accountName, accountType, message) in fakeErrors {
|
||||
let errorLogUserInfo = ErrorLogUserInfoKey.userInfo(sourceName: accountName, sourceID: accountType, errorMessage: message)
|
||||
for (accountName, accountType, operation, message) in fakeErrors {
|
||||
let errorLogUserInfo = ErrorLogUserInfoKey.userInfo(sourceName: accountName, sourceID: accountType, operation: operation, errorMessage: message)
|
||||
NotificationCenter.default.post(name: .appDidEncounterError, object: self, userInfo: errorLogUserInfo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public actor ErrorLogDatabase {
|
||||
|
||||
private let database: FMDatabase
|
||||
|
||||
private static let tableCreationStatements = "CREATE TABLE if not EXISTS errors (id INTEGER PRIMARY KEY AUTOINCREMENT, date REAL NOT NULL, sourceName TEXT NOT NULL, sourceID INTEGER NOT NULL, errorMessage TEXT NOT NULL);"
|
||||
private static let tableCreationStatements = "CREATE TABLE if not EXISTS errors (id INTEGER PRIMARY KEY AUTOINCREMENT, date REAL NOT NULL, sourceName TEXT NOT NULL, sourceID INTEGER NOT NULL, operation TEXT NOT NULL, errorMessage TEXT NOT NULL);"
|
||||
|
||||
private static let pruneLimit = 200
|
||||
|
||||
@@ -31,8 +31,8 @@ public actor ErrorLogDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
public func addEntry(sourceName: String, sourceID: Int, errorMessage: String) {
|
||||
ErrorLogTable.insertEntry(sourceName: sourceName, sourceID: sourceID, errorMessage: errorMessage, database: database)
|
||||
public func addEntry(sourceName: String, sourceID: Int, operation: String, errorMessage: String) {
|
||||
ErrorLogTable.insertEntry(sourceName: sourceName, sourceID: sourceID, operation: operation, errorMessage: errorMessage, database: database)
|
||||
}
|
||||
|
||||
public func allEntries() -> [ErrorLogEntry] {
|
||||
@@ -47,8 +47,9 @@ public actor ErrorLogDatabase {
|
||||
let sourceID = notification.userInfo?[ErrorLogUserInfoKey.sourceID] as? Int else {
|
||||
return
|
||||
}
|
||||
let operation = notification.userInfo?[ErrorLogUserInfoKey.operation] as? String ?? ""
|
||||
Task {
|
||||
await addEntry(sourceName: sourceName, sourceID: sourceID, errorMessage: errorMessage)
|
||||
await addEntry(sourceName: sourceName, sourceID: sourceID, operation: operation, errorMessage: errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,15 @@ public struct ErrorLogEntry: Sendable {
|
||||
public let date: Date
|
||||
public let sourceName: String
|
||||
public let sourceID: Int // 0-99 reserved for AccountType.rawValue. 100 and up for other components.
|
||||
public let operation: String
|
||||
public let errorMessage: String
|
||||
|
||||
public init(id: Int, date: Date, sourceName: String, sourceID: Int, errorMessage: String) {
|
||||
public init(id: Int, date: Date, sourceName: String, sourceID: Int, operation: String, errorMessage: String) {
|
||||
self.id = id
|
||||
self.date = date
|
||||
self.sourceName = sourceName
|
||||
self.sourceID = sourceID
|
||||
self.operation = operation
|
||||
self.errorMessage = errorMessage
|
||||
}
|
||||
|
||||
@@ -29,6 +31,7 @@ public struct ErrorLogEntry: Sendable {
|
||||
static let date = "date"
|
||||
static let sourceName = "sourceName"
|
||||
static let sourceID = "sourceID"
|
||||
static let operation = "operation"
|
||||
static let errorMessage = "errorMessage"
|
||||
}
|
||||
|
||||
@@ -37,6 +40,7 @@ public struct ErrorLogEntry: Sendable {
|
||||
DatabaseKey.date: date.timeIntervalSince1970,
|
||||
DatabaseKey.sourceName: sourceName,
|
||||
DatabaseKey.sourceID: sourceID,
|
||||
DatabaseKey.operation: operation,
|
||||
DatabaseKey.errorMessage: errorMessage
|
||||
]
|
||||
}
|
||||
|
||||
@@ -18,12 +18,14 @@ public struct ErrorLogUserInfoKey {
|
||||
|
||||
public static let sourceName = "sourceName"
|
||||
public static let sourceID = "sourceID" // 0-99 are AccountType raw values. 100 and greater are for other components.
|
||||
public static let operation = "operation"
|
||||
public static let errorMessage = "errorMessage"
|
||||
|
||||
public static func userInfo(sourceName: String, sourceID: Int, errorMessage: String) -> [String: Any] {
|
||||
public static func userInfo(sourceName: String, sourceID: Int, operation: String, errorMessage: String) -> [String: Any] {
|
||||
[
|
||||
Self.sourceName: sourceName,
|
||||
Self.sourceID: sourceID,
|
||||
Self.operation: operation,
|
||||
Self.errorMessage: errorMessage
|
||||
]
|
||||
}
|
||||
|
||||
@@ -13,11 +13,12 @@ struct ErrorLogTable {
|
||||
|
||||
static let name = "errors"
|
||||
|
||||
static func insertEntry(sourceName: String, sourceID: Int, errorMessage: String, database: FMDatabase) {
|
||||
static func insertEntry(sourceName: String, sourceID: Int, operation: String, errorMessage: String, database: FMDatabase) {
|
||||
let dictionary: DatabaseDictionary = [
|
||||
ErrorLogEntry.DatabaseKey.date: Date().timeIntervalSince1970,
|
||||
ErrorLogEntry.DatabaseKey.sourceName: sourceName,
|
||||
ErrorLogEntry.DatabaseKey.sourceID: sourceID,
|
||||
ErrorLogEntry.DatabaseKey.operation: operation,
|
||||
ErrorLogEntry.DatabaseKey.errorMessage: errorMessage
|
||||
]
|
||||
database.insertRow(dictionary, insertType: .normal, tableName: name)
|
||||
@@ -55,7 +56,8 @@ private extension ErrorLogTable {
|
||||
let id = Int(row.longLongInt(forColumn: ErrorLogEntry.DatabaseKey.id))
|
||||
let date = Date(timeIntervalSince1970: row.double(forColumn: ErrorLogEntry.DatabaseKey.date))
|
||||
let sourceID = Int(row.int(forColumn: ErrorLogEntry.DatabaseKey.sourceID))
|
||||
let operation = row.string(forColumn: ErrorLogEntry.DatabaseKey.operation) ?? ""
|
||||
|
||||
return ErrorLogEntry(id: id, date: date, sourceName: sourceName, sourceID: sourceID, errorMessage: errorMessage)
|
||||
return ErrorLogEntry(id: id, date: date, sourceName: sourceName, sourceID: sourceID, operation: operation, errorMessage: errorMessage)
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import Foundation
|
||||
defer { deleteDatabaseFiles(at: path) }
|
||||
|
||||
let database = ErrorLogDatabase(databasePath: path)
|
||||
await database.addEntry(sourceName: "TestAccount", sourceID: 1, errorMessage: "Something went wrong")
|
||||
await database.addEntry(sourceName: "TestAccount", sourceID: 1, operation: "Refreshing", errorMessage: "Something went wrong")
|
||||
|
||||
let entries = await database.allEntries()
|
||||
#expect(entries.count == 1)
|
||||
@@ -36,6 +36,7 @@ import Foundation
|
||||
let entry = entries[0]
|
||||
#expect(entry.sourceName == "TestAccount")
|
||||
#expect(entry.sourceID == 1)
|
||||
#expect(entry.operation == "Refreshing")
|
||||
#expect(entry.errorMessage == "Something went wrong")
|
||||
#expect(entry.id > 0)
|
||||
}
|
||||
@@ -45,9 +46,9 @@ import Foundation
|
||||
defer { deleteDatabaseFiles(at: path) }
|
||||
|
||||
let database = ErrorLogDatabase(databasePath: path)
|
||||
await database.addEntry(sourceName: "First", sourceID: 1, errorMessage: "Error 1")
|
||||
await database.addEntry(sourceName: "Second", sourceID: 2, errorMessage: "Error 2")
|
||||
await database.addEntry(sourceName: "Third", sourceID: 3, errorMessage: "Error 3")
|
||||
await database.addEntry(sourceName: "First", sourceID: 1, operation: "Refreshing", errorMessage: "Error 1")
|
||||
await database.addEntry(sourceName: "Second", sourceID: 2, operation: "Syncing", errorMessage: "Error 2")
|
||||
await database.addEntry(sourceName: "Third", sourceID: 3, operation: "Downloading feed", errorMessage: "Error 3")
|
||||
|
||||
let entries = await database.allEntries()
|
||||
#expect(entries.count == 3)
|
||||
@@ -64,7 +65,7 @@ import Foundation
|
||||
|
||||
let database = ErrorLogDatabase(databasePath: path)
|
||||
for i in 1...210 {
|
||||
await database.addEntry(sourceName: "Account", sourceID: 1, errorMessage: "Error \(i)")
|
||||
await database.addEntry(sourceName: "Account", sourceID: 1, operation: "Refreshing", errorMessage: "Error \(i)")
|
||||
}
|
||||
|
||||
let entriesBeforePrune = await database.allEntries()
|
||||
|
||||
Reference in new issue
Block a user