Improves CheatBase error messages
This commit is contained in:
parent
45665138b2
commit
913cb788a2
@ -80,6 +80,8 @@ class CheatBase: GamesDatabase
|
||||
override init() throws
|
||||
{
|
||||
let fileURL = DatabaseManager.cheatBaseURL
|
||||
guard FileManager.default.fileExists(atPath: fileURL.path) else { throw GamesDatabase.Error.doesNotExist }
|
||||
|
||||
self.connection = try Connection(fileURL.path)
|
||||
|
||||
try super.init()
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
import enum SQLite.Result
|
||||
|
||||
@available(iOS 14, *)
|
||||
extension CheatBaseView
|
||||
{
|
||||
@ -212,9 +214,18 @@ struct CheatBaseView: View
|
||||
Text("Unable to Load Cheats")
|
||||
.font(.title)
|
||||
|
||||
if let error = error as? SQLite.Result
|
||||
{
|
||||
// SQLite.Result implements CustomStringConvertible.description, but not localizedDescription.
|
||||
Text(String(describing: error))
|
||||
.font(.callout)
|
||||
}
|
||||
else
|
||||
{
|
||||
Text(error.localizedDescription)
|
||||
.font(.callout)
|
||||
}
|
||||
}
|
||||
else if let filteredCheats = viewModel.filteredCheats, filteredCheats.isEmpty
|
||||
{
|
||||
Text("Cheat Not Found")
|
||||
|
||||
@ -57,9 +57,17 @@ extension VirtualTable
|
||||
|
||||
extension GamesDatabase
|
||||
{
|
||||
enum Error: Swift.Error
|
||||
enum Error: LocalizedError
|
||||
{
|
||||
case doesNotExist
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self
|
||||
{
|
||||
case .doesNotExist:
|
||||
return NSLocalizedString("The SQLite database could not be found.", comment: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user