From 21b2a869a1ae17e131fc12ea1a471a64f6be6c2f 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 dc9cd1c5..914f3376 100644 --- a/AltStore/Operations/FetchSourceOperation.swift +++ b/AltStore/Operations/FetchSourceOperation.swift @@ -122,7 +122,35 @@ final 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 9d47d6b3..a933a07b 100644 --- a/Shared/Categories/NSError+ALTServerError.m +++ b/Shared/Categories/NSError+ALTServerError.m @@ -37,6 +37,8 @@ NSErrorUserInfoKey const ALTDeviceNameErrorKey = @"deviceName"; NSErrorUserInfoKey const ALTOperatingSystemNameErrorKey = @"ALTOperatingSystemName"; NSErrorUserInfoKey const ALTOperatingSystemVersionErrorKey = @"ALTOperatingSystemVersion"; +NSErrorUserInfoKey const ALTNSCodingPathKey = @"NSCodingPath"; + @implementation NSError (ALTServerError) + (void)load