From e01e31f3d57ebf82189ce7058184f543e8922b6d Mon Sep 17 00:00:00 2001 From: Magesh K <47920326+mahee96@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:18:26 +0530 Subject: [PATCH] [AltStoreCore]: cut out recursion due to customError inheritance in ALTLocalizedError for errorDescription field --- Shared/Errors/ALTLocalizedError.swift | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Shared/Errors/ALTLocalizedError.swift b/Shared/Errors/ALTLocalizedError.swift index 9a486741..926c671c 100755 --- a/Shared/Errors/ALTLocalizedError.swift +++ b/Shared/Errors/ALTLocalizedError.swift @@ -58,13 +58,8 @@ public extension ALTLocalizedError { var errorCode: Int { self.code.rawValue } var errorDescription: String? { - guard (self as NSError).localizedFailureReason == nil else { - // Error has localizedFailureReason, so return nil to construct localizedDescription from it + localizedFailureReason. - return nil - } - - // Otherwise, return failureReason for localizedDescription to avoid system prepending "Operation Failed" message. - return self.failureReason + // Use errorFailure directly without relying on bridging to NSError + return self.errorFailure ?? self.failureReason } var failureReason: String? { @@ -72,15 +67,13 @@ public extension ALTLocalizedError } var errorUserInfo: [String : Any] { - var userInfo: [String: Any?] = [ + let userInfo: [String: Any?] = [ NSLocalizedFailureErrorKey: self.errorFailure, ALTLocalizedTitleErrorKey: self.errorTitle, ALTSourceFileErrorKey: self.sourceFile, - ALTSourceLineErrorKey: self.sourceLine, + ALTSourceLineErrorKey: self.sourceLine, ] - - userInfo.merge(self.userInfoValues) { (_, new) in new } - + return userInfo.compactMapValues { $0 } } @@ -107,7 +100,7 @@ public extension ALTErrorCode { static var errorDomain: String { let typeName = String(reflecting: Self.self) // "\(Self.self)" doesn't include module name, but String(reflecting:) does. - let errorDomain = typeName.replacingOccurrences(of: "ErrorCode", with: "Error").replacingOccurrences(of: "Error.Code", with: "Error") + let errorDomain = typeName.replacingOccurrences(of: "ErrorCode", with: "Error") return errorDomain } }