From a6e5c32166decf8e60b4a8350b759696d32b74fd Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 11 Apr 2022 13:42:31 -0700 Subject: [PATCH] Fixes Core Data error when not connected to internet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- Shared/Extensions/NSError+AltStore.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Shared/Extensions/NSError+AltStore.swift b/Shared/Extensions/NSError+AltStore.swift index 77096a27..ded2472a 100644 --- a/Shared/Extensions/NSError+AltStore.swift +++ b/Shared/Extensions/NSError+AltStore.swift @@ -67,8 +67,23 @@ extension NSError userInfo[NSLocalizedFailureReasonErrorKey] = self.localizedFailureReason userInfo[NSLocalizedRecoverySuggestionErrorKey] = self.localizedRecoverySuggestion - // Remove non-ObjC-compliant userInfo values. - userInfo["NSCodingPath"] = nil + // Remove userInfo values that don't conform to NSSecureEncoding. + 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) return error