mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-20 04:03:26 +01:00
[ToastView]: Fix: restore back to printing localizedDescription as before
This commit is contained in:
@@ -65,13 +65,23 @@ class ToastView: RSTToastView
|
|||||||
self.opensErrorLog = opensLog
|
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 error = error as NSError
|
||||||
|
let mode = mode == .fullError ? ErrorProcessing.InfoMode.fullError : ErrorProcessing.InfoMode.localizedDescription
|
||||||
|
|
||||||
let text = error.localizedTitle ?? NSLocalizedString("Operation Failed", comment: "")
|
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)
|
self.init(text: text, detailText: detailText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ extension LaunchViewController
|
|||||||
let errorDesc = ErrorProcessing(.fullError).getDescription(error: error as NSError)
|
let errorDesc = ErrorProcessing(.fullError).getDescription(error: error as NSError)
|
||||||
print("Failed to update sources on launch. \(errorDesc)")
|
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.addTarget(self.destinationViewController, action: #selector(TabBarController.presentSources), for: .touchUpInside)
|
||||||
toastView.show(in: self.destinationViewController.selectedViewController ?? self.destinationViewController)
|
toastView.show(in: self.destinationViewController.selectedViewController ?? self.destinationViewController)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class ErrorProcessing {
|
|||||||
self.recur = recur
|
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
|
// if unique was requested and if this error is duplicate, ignore processing it
|
||||||
let serializedError = "\(error)"
|
let serializedError = "\(error)"
|
||||||
if unique && errors.contains(serializedError) {
|
if unique && errors.contains(serializedError) {
|
||||||
@@ -39,7 +39,7 @@ class ErrorProcessing {
|
|||||||
var desc = ""
|
var desc = ""
|
||||||
switch (info){
|
switch (info){
|
||||||
case .localizedDescription:
|
case .localizedDescription:
|
||||||
title = (error.localizedTitle.map{$0+"\n"} ?? "")
|
title = !ignoreTitle ? (error.localizedTitle.map{$0+"\n"} ?? "") : ""
|
||||||
desc = error.localizedDescription
|
desc = error.localizedDescription
|
||||||
case .fullError:
|
case .fullError:
|
||||||
desc = serializedError
|
desc = serializedError
|
||||||
@@ -54,13 +54,14 @@ class ErrorProcessing {
|
|||||||
return getDescriptionText(error: error)
|
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 = ""
|
var description = ""
|
||||||
|
|
||||||
// process current error only if recur was not requested
|
// process current error only if recur was not requested
|
||||||
let processMoreErrors = recur ? recurseErrors : {_ in ""}
|
let processMoreErrors = recur ? recurseErrors : {_ in ""}
|
||||||
|
|
||||||
@@ -74,7 +75,9 @@ class ErrorProcessing {
|
|||||||
let error = underlyingError as NSError
|
let error = underlyingError as NSError
|
||||||
description += processError(error, getMoreErrors: processMoreErrors)
|
description += processError(error, getMoreErrors: processMoreErrors)
|
||||||
} else {
|
} 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
|
return description
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user