[Shared] Includes CodingPath in Source errors’ debug description (if available)

This commit is contained in:
Riley Testut
2023-10-10 15:13:40 -05:00
committed by Magesh K
parent 34c503da4b
commit 21b2a869a1
3 changed files with 33 additions and 1 deletions

View File

@@ -122,7 +122,35 @@ final class FetchSourceOperation: ResultOperation<Source>
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)

View File

@@ -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,

View File

@@ -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