From 69a01a3262c3e8d7a5a6be1c10ab74309acc2440 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 8 Jan 2024 14:27:01 -0600 Subject: [PATCH] [AltStoreCore] Includes more context when logging Patreon account errors Includes full decoding path if possible. --- .../Operations/UpdatePatronsOperation.swift | 4 ++-- AltStoreCore/Patreon/PatreonAPI.swift | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/AltStore/Operations/UpdatePatronsOperation.swift b/AltStore/Operations/UpdatePatronsOperation.swift index 6aa939e1..14a21565 100644 --- a/AltStore/Operations/UpdatePatronsOperation.swift +++ b/AltStore/Operations/UpdatePatronsOperation.swift @@ -89,9 +89,9 @@ final class UpdatePatronsOperation: ResultOperation Logger.main.notice("Updated Friend Zone Patrons! Refresh ID: \(response.refreshID, privacy: .public)") } - catch + catch let error as NSError { - Logger.main.error("Failed to update Friend Zone Patrons. \(error.localizedDescription, privacy: .public)") + Logger.main.error("Failed to update Friend Zone Patrons. \(error.localizedDebugDescription ?? error.localizedDescription, privacy: .public)") self.finish(.failure(error)) } } diff --git a/AltStoreCore/Patreon/PatreonAPI.swift b/AltStoreCore/Patreon/PatreonAPI.swift index b197c0fe..a5c43298 100644 --- a/AltStoreCore/Patreon/PatreonAPI.swift +++ b/AltStoreCore/Patreon/PatreonAPI.swift @@ -180,6 +180,28 @@ public extension PatreonAPI completion(.failure(PatreonAPIError(.notAuthenticated))) } + case .failure(let error as DecodingError): + do + { + let nsError = error as NSError + guard let codingPath = nsError.userInfo[ALTNSCodingPathKey] as? [CodingKey] else { throw error } + + let rawComponents = codingPath.map { $0.intValue?.description ?? $0.stringValue } + let pathDescription = rawComponents.joined(separator: " > ") + + let localizedDescription = nsError.localizedDebugDescription ?? nsError.localizedDescription + let debugDescription = localizedDescription + " Path: " + pathDescription + + var userInfo = nsError.userInfo + userInfo[NSDebugDescriptionErrorKey] = debugDescription + throw NSError(domain: nsError.domain, code: nsError.code, userInfo: userInfo) + } + catch let error as NSError + { + Logger.main.error("Failed to fetch Patreon account. \(error.localizedDebugDescription ?? error.localizedDescription, privacy: .public)") + completion(.failure(error)) + } + case .failure(let error as NSError): Logger.main.error("Failed to fetch Patreon account. \(error.localizedDebugDescription ?? error.localizedDescription, privacy: .public)") completion(.failure(error))