Improves CheatBase error messages
This commit is contained in:
parent
45665138b2
commit
913cb788a2
@ -80,6 +80,8 @@ class CheatBase: GamesDatabase
|
|||||||
override init() throws
|
override init() throws
|
||||||
{
|
{
|
||||||
let fileURL = DatabaseManager.cheatBaseURL
|
let fileURL = DatabaseManager.cheatBaseURL
|
||||||
|
guard FileManager.default.fileExists(atPath: fileURL.path) else { throw GamesDatabase.Error.doesNotExist }
|
||||||
|
|
||||||
self.connection = try Connection(fileURL.path)
|
self.connection = try Connection(fileURL.path)
|
||||||
|
|
||||||
try super.init()
|
try super.init()
|
||||||
|
|||||||
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
|
import enum SQLite.Result
|
||||||
|
|
||||||
@available(iOS 14, *)
|
@available(iOS 14, *)
|
||||||
extension CheatBaseView
|
extension CheatBaseView
|
||||||
{
|
{
|
||||||
@ -212,8 +214,17 @@ struct CheatBaseView: View
|
|||||||
Text("Unable to Load Cheats")
|
Text("Unable to Load Cheats")
|
||||||
.font(.title)
|
.font(.title)
|
||||||
|
|
||||||
Text(error.localizedDescription)
|
if let error = error as? SQLite.Result
|
||||||
.font(.callout)
|
{
|
||||||
|
// 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
|
else if let filteredCheats = viewModel.filteredCheats, filteredCheats.isEmpty
|
||||||
{
|
{
|
||||||
|
|||||||
@ -57,9 +57,17 @@ extension VirtualTable
|
|||||||
|
|
||||||
extension GamesDatabase
|
extension GamesDatabase
|
||||||
{
|
{
|
||||||
enum Error: Swift.Error
|
enum Error: LocalizedError
|
||||||
{
|
{
|
||||||
case doesNotExist
|
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