improve error codes

This commit is contained in:
leminlimez committed 2025-06-18 18:47:27 -04:00
1 parent d45a64bb19
commit 54aa8e20a3
2 files changed
+46 -7

No files matched your search

@@ -0,0 +1,30 @@
//
// ApplyError.swift
// Pocket Poster
//
// Created by lemin on 6/18/25.
//
import Foundation
enum ApplyError: LocalizedError {
// Throw when the app hash is incorrect
case wrongAppHash
// Throw when the collections need to be reset
case collectionsNeedsReset
// Throw in all other cases
case unexpected(info: String)
public var errorDescription: String? {
switch self {
case .wrongAppHash:
return "Your app hash is incorrect. Please set it again."
case .collectionsNeedsReset:
return "The folder is improperly set up. Please tap \"Reset Collections\" and try again."
case .unexpected(let info):
return info
}
}
}
+16 -7
View File
@@ -75,8 +75,8 @@ struct ContentView: View {
try pbManager.applyTendies(appHash: pbHash) try pbManager.applyTendies(appHash: pbHash)
SymHandler.cleanup() // just to be extra sure SymHandler.cleanup() // just to be extra sure
try? FileManager.default.removeItem(at: pbManager.getTendiesStoreURL()) try? FileManager.default.removeItem(at: pbManager.getTendiesStoreURL())
Haptic.shared.notify(.success)
UIApplication.shared.dismissAlert(animated: false) UIApplication.shared.dismissAlert(animated: false)
Haptic.shared.notify(.success)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: { DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: {
pbManager.selectedTendies.removeAll() pbManager.selectedTendies.removeAll()
UIApplication.shared.confirmAlert(title: "Success!", body: "The PosterBoard app will now open. Please close it from the app switcher.", onOK: { UIApplication.shared.confirmAlert(title: "Success!", body: "The PosterBoard app will now open. Please close it from the app switcher.", onOK: {
@@ -87,13 +87,12 @@ struct ContentView: View {
} }
}, noCancel: true) }, noCancel: true)
}) })
} catch CocoaError.fileWriteUnknown {
presentError(ApplyError.wrongAppHash)
} catch CocoaError.fileWriteFileExists {
presentError(ApplyError.collectionsNeedsReset)
} catch { } catch {
Haptic.shared.notify(.error) presentError(ApplyError.unexpected(info: error.localizedDescription))
SymHandler.cleanup()
UIApplication.shared.dismissAlert(animated: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: {
UIApplication.shared.alert(body: error.localizedDescription)
})
} }
} }
}) { }) {
@@ -173,6 +172,16 @@ struct ContentView: View {
pbManager.selectedTendies.remove(atOffsets: offsets) pbManager.selectedTendies.remove(atOffsets: offsets)
} }
func presentError(_ error: ApplyError) {
SymHandler.cleanup()
UIApplication.shared.dismissAlert(animated: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: {
lastError = error.localizedDescription
Haptic.shared.notify(.error)
showErrorAlert = true
})
}
init() { init() {
// Fix file picker // Fix file picker
let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.fix_init(forOpeningContentTypes:asCopy:)))! let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.fix_init(forOpeningContentTypes:asCopy:)))!