mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Simplify error messages
This commit is contained in:
1 parent
f5dc68fc6f
commit
9ef5e2c8eb
4 files changed
+17
-52
No files matched your search
@@ -367,17 +367,9 @@ extension Database {
|
||||
}
|
||||
|
||||
if (try? viewExists(tableName, in: schemaName)) == true {
|
||||
if schemaSource == nil {
|
||||
throw DatabaseError(message: """
|
||||
The database view '\(tableName)' has no primary key. \
|
||||
To support views, provide a custom schema source in Configuration.schemaSource.
|
||||
""")
|
||||
} else {
|
||||
throw DatabaseError(message: """
|
||||
The database view '\(tableName)' has no primary key, \
|
||||
according to Configuration.schemaSource.
|
||||
""")
|
||||
}
|
||||
throw DatabaseError(message: """
|
||||
database view \(tableName) has no primary key
|
||||
""")
|
||||
} else {
|
||||
throw DatabaseError.noSuchTable(tableName)
|
||||
}
|
||||
@@ -404,18 +396,9 @@ extension Database {
|
||||
if case .SQLITE_ERROR = error.resultCode,
|
||||
(try? viewExists(tableName)) == true
|
||||
{
|
||||
if schemaSource == nil {
|
||||
fatalError("""
|
||||
Filtering by primary key is not available on the database view '\(tableName)'. \
|
||||
Instead, use `filter(Column("...") == value)`, or provide \
|
||||
a custom schema source in Configuration.schemaSource.
|
||||
""")
|
||||
} else {
|
||||
fatalError("""
|
||||
Filtering by primary key requires a single-column primary key in the view '\(tableName)'. \
|
||||
No such primary key is configured by Configuration.schemaSource.
|
||||
""")
|
||||
}
|
||||
throw DatabaseError(message: """
|
||||
database view \(tableName) has no primary key
|
||||
""")
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ let captains = try Captain.fetchAll(db)
|
||||
let captainCount = try Captain.fetchCount(db)
|
||||
|
||||
// KO: Requires extra configuration
|
||||
// SQLite error 1: The database view 'captain' has no primary key.
|
||||
// SQLite error 1: database view captain has no primary key
|
||||
var bob = try Captain.find(db, id: "bob")
|
||||
bob.name = "Bobby"
|
||||
// SQLite error 1: cannot modify captain because it is a view
|
||||
|
||||
@@ -827,20 +827,10 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest {
|
||||
// or unique index).
|
||||
guard let columns = try db.columnsForUniqueKey(key.keys, in: databaseTableName) else {
|
||||
if (try? db.viewExists(databaseTableName)) == true {
|
||||
if db.schemaSource == nil {
|
||||
fatalError("""
|
||||
view \(databaseTableName) has no unique key on column(s) \
|
||||
\(key.keys.sorted().joined(separator: ", ")). To support \
|
||||
keys in views, provide a custom schema source in \
|
||||
Configuration.schemaSource.
|
||||
""")
|
||||
} else {
|
||||
fatalError("""
|
||||
view \(databaseTableName) has no unique key on column(s) \
|
||||
\(key.keys.sorted().joined(separator: ", ")), \
|
||||
according to Configuration.schemaSource.
|
||||
""")
|
||||
}
|
||||
fatalError("""
|
||||
database view \(databaseTableName) has no unique key on column(s) \
|
||||
\(key.keys.sorted().joined(separator: ", "))
|
||||
""")
|
||||
} else {
|
||||
fatalError("""
|
||||
table \(databaseTableName) has no unique key on column(s) \
|
||||
|
||||
@@ -27,14 +27,10 @@ class PrimaryKeyInfoTests: GRDBTestCase {
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssertEqual(error.message, """
|
||||
The database view 'items' has no primary key. \
|
||||
To support views, provide a custom schema source \
|
||||
in Configuration.schemaSource.
|
||||
database view items has no primary key
|
||||
""")
|
||||
XCTAssertEqual(error.description, """
|
||||
SQLite error 1: The database view 'items' has no primary key. \
|
||||
To support views, provide a custom schema source \
|
||||
in Configuration.schemaSource.
|
||||
SQLite error 1: database view items has no primary key
|
||||
""")
|
||||
}
|
||||
}
|
||||
@@ -282,12 +278,10 @@ class PrimaryKeyInfoTests: GRDBTestCase {
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssertEqual(error.message, """
|
||||
The database view 'playerView' has no primary key, \
|
||||
according to Configuration.schemaSource.
|
||||
database view playerView has no primary key
|
||||
""")
|
||||
XCTAssertEqual(error.description, """
|
||||
SQLite error 1: The database view 'playerView' has no primary key, \
|
||||
according to Configuration.schemaSource.
|
||||
SQLite error 1: database view playerView has no primary key
|
||||
""")
|
||||
}
|
||||
}
|
||||
@@ -322,12 +316,10 @@ class PrimaryKeyInfoTests: GRDBTestCase {
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssertEqual(error.message, """
|
||||
The database view 'playerView' has no primary key, \
|
||||
according to Configuration.schemaSource.
|
||||
database view playerView has no primary key
|
||||
""")
|
||||
XCTAssertEqual(error.description, """
|
||||
SQLite error 1: The database view 'playerView' has no primary key, \
|
||||
according to Configuration.schemaSource.
|
||||
SQLite error 1: database view playerView has no primary key
|
||||
""")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user