Fixes “Core Data error” when error is thrown while parsing Source JSON

‘NSCodingPath’ is an array of non-ObjC values, but because it’s an array the array itself conforms to NSSecureCoding via NSArray bridging.

We now make sure every element in an array or dictionary also conforms to NSSecureCoding to keep it in an error’s userInfo for serialization.
This commit is contained in:
Riley Testut
2023-05-26 15:05:02 -05:00
committed by Magesh K
parent 99db3dc086
commit c83d486269

View File

@@ -79,7 +79,20 @@ public extension NSError
userInfo[NSDebugDescriptionErrorKey] = self.localizedDebugDescription
// Remove userInfo values that don't conform to NSSecureEncoding.
userInfo = userInfo.filter { (key, value) in
return (value as AnyObject) is NSSecureCoding
guard let secureCodable = value as? NSSecureCoding else { return false }
switch secureCodable
{
case let array as NSArray:
let isSecureCodable = array.allSatisfy({ $0 is NSSecureCoding })
return isSecureCodable
case let dictionary as NSDictionary:
let isSecureCodable = dictionary.allValues.allSatisfy({ $0 is NSSecureCoding })
return isSecureCodable
default: return true
}
}
// Sanitize underlying errors.