From a5e11b06261aa64219b57a9a118a8214e2bf431f Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 10 Oct 2023 15:13:40 -0500 Subject: [PATCH] =?UTF-8?q?[Shared]=20Includes=20CodingPath=20in=20Source?= =?UTF-8?q?=20errors=E2=80=99=20debug=20description=20(if=20available)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Operations/FetchSourceOperation.swift | 30 ++++++++++++++++++- Shared/Categories/NSError+ALTServerError.h | 2 ++ Shared/Categories/NSError+ALTServerError.m | 2 ++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/AltStore/Operations/FetchSourceOperation.swift b/AltStore/Operations/FetchSourceOperation.swift index 065aefb2..89d495b6 100644 --- a/AltStore/Operations/FetchSourceOperation.swift +++ b/AltStore/Operations/FetchSourceOperation.swift @@ -114,7 +114,35 @@ class FetchSourceOperation: ResultOperation decoder.managedObjectContext = childContext decoder.sourceURL = self.sourceURL - let source = try decoder.decode(Source.self, from: data) + let source: Source + + do + { + source = try decoder.decode(Source.self, from: data) + } + catch let error as DecodingError + { + 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: " > ") + + var userInfo = nsError.userInfo + + if let debugDescription = nsError.localizedDebugDescription + { + let detailedDescription = debugDescription + "\n\n" + pathDescription + userInfo[NSDebugDescriptionErrorKey] = detailedDescription + } + else + { + userInfo[NSDebugDescriptionErrorKey] = pathDescription + } + + throw NSError(domain: nsError.domain, code: nsError.code, userInfo: userInfo) + } + let identifier = source.identifier try self.verify(source, response: response) diff --git a/Shared/Categories/NSError+ALTServerError.h b/Shared/Categories/NSError+ALTServerError.h index 173a4d38..7368e4e0 100644 --- a/Shared/Categories/NSError+ALTServerError.h +++ b/Shared/Categories/NSError+ALTServerError.h @@ -19,6 +19,8 @@ extern NSErrorUserInfoKey const ALTDeviceNameErrorKey; extern NSErrorUserInfoKey const ALTOperatingSystemNameErrorKey; extern NSErrorUserInfoKey const ALTOperatingSystemVersionErrorKey; +extern NSErrorUserInfoKey const ALTNSCodingPathKey; + typedef NS_ERROR_ENUM(AltServerErrorDomain, ALTServerError) { ALTServerErrorUnderlyingError = -1, diff --git a/Shared/Categories/NSError+ALTServerError.m b/Shared/Categories/NSError+ALTServerError.m index 3394b6ad..c77a9253 100644 --- a/Shared/Categories/NSError+ALTServerError.m +++ b/Shared/Categories/NSError+ALTServerError.m @@ -30,6 +30,8 @@ NSErrorUserInfoKey const ALTDeviceNameErrorKey = @"deviceName"; NSErrorUserInfoKey const ALTOperatingSystemNameErrorKey = @"ALTOperatingSystemName"; NSErrorUserInfoKey const ALTOperatingSystemVersionErrorKey = @"ALTOperatingSystemVersion"; +NSErrorUserInfoKey const ALTNSCodingPathKey = @"NSCodingPath"; + @implementation NSError (ALTServerError) + (void)load