refactor: Reduce duplicate code with Error.message()

also add some things I forgot in previous commits
This commit is contained in:
naturecodevoid
2023-06-01 07:36:40 -07:00
parent 175b5bec95
commit 7bb1c1cf05
6 changed files with 21 additions and 14 deletions

View File

@@ -0,0 +1,13 @@
//
// Error+Message.swift
// SideStore
//
// Created by naturecodevoid on 5/30/23.
// Copyright © 2023 SideStore. All rights reserved.
//
extension Error {
func message() -> String {
(self as? LocalizedError)?.failureReason ?? self.localizedDescription
}
}

View File

@@ -152,7 +152,7 @@ final class LaunchViewController: RSTLaunchViewController, UIDocumentPickerDeleg
try start(pairing_file, documentsDirectory)
} catch {
try! FileManager.default.removeItem(at: FileManager.default.documentsDirectory.appendingPathComponent("\(pairingFileName)"))
displayError("minimuxer failed to start, please restart SideStore. \((error as? LocalizedError)?.failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")")
displayError("minimuxer failed to start, please restart SideStore. \(error.message())")
}
set_debug(UserDefaults.shared.isDebugLoggingEnabled)
start_auto_mounter(documentsDirectory)

View File

@@ -191,12 +191,6 @@ You should only enable Developer Mode if you meet one of the following requireme
"DevModeView.password" = "Password";
"DevModeView.incorrectPassword" = "Incorrect password.";
"DevModeView.read" = "Read the text!";
"DevModeView.console" = "Console";
"DevModeView.dataExplorer" = "Data File Explorer";
"DevModeView.tmpExplorer" = "Temporary File Explorer";
"DevModeView.skipResign" = "Skip Resign";
"DevModeView.footer" = "Skip Resign should only be used when you have an IPA that you have self signed. Otherwise, it will break things, and might make SideStore crash (there is absolutely no error handling and everything is expected to work).";
"DevModeView.minimuxer" = "minimuxer debug actions";
"DevModeView.General.header" = "General";
"DevModeView.General.console" = "Console";
"DevModeView.General.unstableFeaturesNightlyOnly" = "Unstable Features are only available on nightly builds, PR builds and debug builds.";

View File

@@ -140,26 +140,26 @@ private extension SceneDelegate
}
case "sidejit-enable":
guard UnstableFeatures.enabled(.jitUrlScheme) else { return UIApplication.alertOk(title: "JIT URL scheme unstable feature is not enabled", message: nil) }
guard UnstableFeatures.enabled(.jitUrlScheme) else { return UIApplication.alert(title: "JIT URL scheme unstable feature is not enabled", message: nil) }
if let bundleID = queryItems["bid"] {
DispatchQueue.main.async {
do {
try debug_app(bundleID)
} catch {
UIApplication.alertOk(title: "An error occurred when enabling JIT", message: error.localizedDescription)
UIApplication.alert(title: "An error occurred when enabling JIT", message: error.message())
}
}
} else if let processID = queryItems["pid"] {
DispatchQueue.main.async {
do {
guard let processID = UInt32(processID) else { return UIApplication.alertOk(title: "An error occurred when enabling JIT", message: "Process ID is not a valid unsigned integer") }
guard let processID = UInt32(processID) else { return UIApplication.alert(title: "An error occurred when enabling JIT", message: "Process ID is not a valid unsigned integer") }
try attach_debugger(processID)
} catch {
UIApplication.alertOk(title: "An error occurred when enabling JIT", message: error.localizedDescription)
UIApplication.alert(title: "An error occurred when enabling JIT", message: error.message())
}
}
} else { return UIApplication.alertOk(title: "An error occurred when enabling JIT", message: "Please specify a bundle ID using the `bid` query parameter or a process ID using `pid` query parameter") }
} else { return UIApplication.alert(title: "An error occurred when enabling JIT", message: "Please specify a bundle ID using the `bid` query parameter or a process ID using `pid` query parameter") }
default: break
}

View File

@@ -88,7 +88,7 @@ struct AsyncFallibleButton<Label: View>: View {
} catch {
DispatchQueue.main.async {
state = .error
errorAlertMessage = (error as? LocalizedError)?.failureReason ?? error.localizedDescription
errorAlertMessage = error.message()
showErrorAlert = true
}
}

View File

@@ -315,7 +315,7 @@ extension OnboardingView {
try! FileManager.default.removeItem(at: FileManager.default.documentsDirectory.appendingPathComponent("\(pairingFileName)"))
NotificationManager.shared.reportError(error: error)
debugPrint("minimuxer failed to start, please restart SideStore.", error)
// displayError("minimuxer failed to start, please restart SideStore. \((error as? LocalizedError)?.failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")")
// displayError("minimuxer failed to start, please restart SideStore. \(error.message())")
}
start_auto_mounter(documentsDirectory)
}