Improves CheatBase error messages

This commit is contained in:
Riley Testut 2023-02-06 14:45:48 -06:00
parent 45665138b2
commit 913cb788a2
3 changed files with 24 additions and 3 deletions

View File

@ -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()

View File

@ -8,6 +8,8 @@
import SwiftUI
import enum SQLite.Result
@available(iOS 14, *)
extension CheatBaseView
{
@ -212,8 +214,17 @@ struct CheatBaseView: View
Text("Unable to Load Cheats")
.font(.title)
Text(error.localizedDescription)
.font(.callout)
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
{

View File

@ -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: "")
}
}
}
}