diff --git a/AltStore/Components/ToastView.swift b/AltStore/Components/ToastView.swift index f940b4ac..b563d811 100644 --- a/AltStore/Components/ToastView.swift +++ b/AltStore/Components/ToastView.swift @@ -65,13 +65,23 @@ class ToastView: RSTToastView self.opensErrorLog = opensLog } - convenience init(error: Error) + enum InfoMode: String { + case fullError + case localizedDescription + } + + convenience init(error: Error){ + self.init(error: error, mode: .localizedDescription) + } + + convenience init(error: Error, mode: InfoMode) { let error = error as NSError + let mode = mode == .fullError ? ErrorProcessing.InfoMode.fullError : ErrorProcessing.InfoMode.localizedDescription let text = error.localizedTitle ?? NSLocalizedString("Operation Failed", comment: "") - let detailText = ErrorProcessing(.fullError).getDescription(error: error) - + let detailText = ErrorProcessing(mode).getDescription(error: error) + self.init(text: text, detailText: detailText) } diff --git a/AltStore/LaunchViewController.swift b/AltStore/LaunchViewController.swift index 13c42c80..d06242c6 100644 --- a/AltStore/LaunchViewController.swift +++ b/AltStore/LaunchViewController.swift @@ -316,7 +316,7 @@ extension LaunchViewController let errorDesc = ErrorProcessing(.fullError).getDescription(error: error as NSError) print("Failed to update sources on launch. \(errorDesc)") - let toastView = ToastView(error: error) + let toastView = ToastView(error: error, mode: .fullError) toastView.addTarget(self.destinationViewController, action: #selector(TabBarController.presentSources), for: .touchUpInside) toastView.show(in: self.destinationViewController.selectedViewController ?? self.destinationViewController) } diff --git a/SideStore/Utils/dignostics/errors/ErrorProcessing.swift b/SideStore/Utils/dignostics/errors/ErrorProcessing.swift index 15489f58..3e46c659 100644 --- a/SideStore/Utils/dignostics/errors/ErrorProcessing.swift +++ b/SideStore/Utils/dignostics/errors/ErrorProcessing.swift @@ -27,7 +27,7 @@ class ErrorProcessing { self.recur = recur } - private func processError(_ error: NSError, getMoreErrors: (_ error: NSError)->String) -> String{ + private func processError(_ error: NSError, ignoreTitle: Bool = false, getMoreErrors: (_ error: NSError)->String) -> String{ // if unique was requested and if this error is duplicate, ignore processing it let serializedError = "\(error)" if unique && errors.contains(serializedError) { @@ -39,7 +39,7 @@ class ErrorProcessing { var desc = "" switch (info){ case .localizedDescription: - title = (error.localizedTitle.map{$0+"\n"} ?? "") + title = !ignoreTitle ? (error.localizedTitle.map{$0+"\n"} ?? "") : "" desc = error.localizedDescription case .fullError: desc = serializedError @@ -54,13 +54,14 @@ class ErrorProcessing { return getDescriptionText(error: error) } - private lazy var recurseErrors = { error in - self.getDescriptionText(error: error) // recursively process underlying error(s) if any - } - func getDescriptionText(error: NSError) -> String{ + func getDescriptionText(error: NSError,_ depth: Int = 0) -> String{ + // closure + let recurseErrors = { error in + self.getDescriptionText(error: error, depth+1) // recursively process underlying error(s) if any + } + var description = "" - // process current error only if recur was not requested let processMoreErrors = recur ? recurseErrors : {_ in ""} @@ -74,7 +75,9 @@ class ErrorProcessing { let error = underlyingError as NSError description += processError(error, getMoreErrors: processMoreErrors) } else { - description += processError(error, getMoreErrors: processMoreErrors) + // ignore the title for the base error since we wanted this to be description + let isBaseError = (depth == 0) + description += processError(error, ignoreTitle: isBaseError, getMoreErrors: processMoreErrors) } return description }