mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-18 19:23:43 +01:00
Fixes Core Data error when not connected to internet
NSError.sanitizedForCoreData() now sanitizes _all_ user info values (including for underlying errors) to ensure they all conform to NSSecureCoding, rather than just removing “NSCodingPath” value (if it exists).
This commit is contained in:
@@ -67,8 +67,23 @@ extension NSError
|
|||||||
userInfo[NSLocalizedFailureReasonErrorKey] = self.localizedFailureReason
|
userInfo[NSLocalizedFailureReasonErrorKey] = self.localizedFailureReason
|
||||||
userInfo[NSLocalizedRecoverySuggestionErrorKey] = self.localizedRecoverySuggestion
|
userInfo[NSLocalizedRecoverySuggestionErrorKey] = self.localizedRecoverySuggestion
|
||||||
|
|
||||||
// Remove non-ObjC-compliant userInfo values.
|
// Remove userInfo values that don't conform to NSSecureEncoding.
|
||||||
userInfo["NSCodingPath"] = nil
|
userInfo = userInfo.filter { (key, value) in
|
||||||
|
return (value as AnyObject) is NSSecureCoding
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanitize underlying errors.
|
||||||
|
if let underlyingError = userInfo[NSUnderlyingErrorKey] as? Error
|
||||||
|
{
|
||||||
|
let sanitizedError = (underlyingError as NSError).sanitizedForCoreData()
|
||||||
|
userInfo[NSUnderlyingErrorKey] = sanitizedError
|
||||||
|
}
|
||||||
|
|
||||||
|
if #available(iOS 14.5, *), let underlyingErrors = userInfo[NSMultipleUnderlyingErrorsKey] as? [Error]
|
||||||
|
{
|
||||||
|
let sanitizedErrors = underlyingErrors.map { ($0 as NSError).sanitizedForCoreData() }
|
||||||
|
userInfo[NSMultipleUnderlyingErrorsKey] = sanitizedErrors
|
||||||
|
}
|
||||||
|
|
||||||
let error = NSError(domain: self.domain, code: self.code, userInfo: userInfo)
|
let error = NSError(domain: self.domain, code: self.code, userInfo: userInfo)
|
||||||
return error
|
return error
|
||||||
|
|||||||
Reference in New Issue
Block a user