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