Skip to content

Commit 3e1a711

Browse files
committed
Simplify error messages
1 parent d698bc7 commit 3e1a711

File tree

4 files changed

+17
-52
lines changed

4 files changed

+17
-52
lines changed

GRDB/Core/Database+Schema.swift

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -367,17 +367,9 @@ extension Database {
367367
}
368368

369369
if (try? viewExists(tableName, in: schemaName)) == true {
370-
if schemaSource == nil {
371-
throw DatabaseError(message: """
372-
The database view '\(tableName)' has no primary key. \
373-
To support views, provide a custom schema source in Configuration.schemaSource.
374-
""")
375-
} else {
376-
throw DatabaseError(message: """
377-
The database view '\(tableName)' has no primary key, \
378-
according to Configuration.schemaSource.
379-
""")
380-
}
370+
throw DatabaseError(message: """
371+
database view \(tableName) has no primary key
372+
""")
381373
} else {
382374
throw DatabaseError.noSuchTable(tableName)
383375
}
@@ -404,18 +396,9 @@ extension Database {
404396
if case .SQLITE_ERROR = error.resultCode,
405397
(try? viewExists(tableName)) == true
406398
{
407-
if schemaSource == nil {
408-
fatalError("""
409-
Filtering by primary key is not available on the database view '\(tableName)'. \
410-
Instead, use `filter(Column("...") == value)`, or provide \
411-
a custom schema source in Configuration.schemaSource.
412-
""")
413-
} else {
414-
fatalError("""
415-
Filtering by primary key requires a single-column primary key in the view '\(tableName)'. \
416-
No such primary key is configured by Configuration.schemaSource.
417-
""")
418-
}
399+
throw DatabaseError(message: """
400+
database view \(tableName) has no primary key
401+
""")
419402
} else {
420403
throw error
421404
}

GRDB/Documentation.docc/ViewRecords.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let captains = try Captain.fetchAll(db)
1414
let captainCount = try Captain.fetchCount(db)
1515

1616
// KO: Requires extra configuration
17-
// SQLite error 1: The database view 'captain' has no primary key.
17+
// SQLite error 1: database view captain has no primary key
1818
var bob = try Captain.find(db, id: "bob")
1919
bob.name = "Bobby"
2020
// SQLite error 1: cannot modify captain because it is a view

GRDB/QueryInterface/Request/RequestProtocols.swift

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -827,20 +827,10 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest {
827827
// or unique index).
828828
guard let columns = try db.columnsForUniqueKey(key.keys, in: databaseTableName) else {
829829
if (try? db.viewExists(databaseTableName)) == true {
830-
if db.schemaSource == nil {
831-
fatalError("""
832-
view \(databaseTableName) has no unique key on column(s) \
833-
\(key.keys.sorted().joined(separator: ", ")). To support \
834-
keys in views, provide a custom schema source in \
835-
Configuration.schemaSource.
836-
""")
837-
} else {
838-
fatalError("""
839-
view \(databaseTableName) has no unique key on column(s) \
840-
\(key.keys.sorted().joined(separator: ", ")), \
841-
according to Configuration.schemaSource.
842-
""")
843-
}
830+
fatalError("""
831+
database view \(databaseTableName) has no unique key on column(s) \
832+
\(key.keys.sorted().joined(separator: ", "))
833+
""")
844834
} else {
845835
fatalError("""
846836
table \(databaseTableName) has no unique key on column(s) \

Tests/GRDBTests/PrimaryKeyInfoTests.swift

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ class PrimaryKeyInfoTests: GRDBTestCase {
2727
} catch let error as DatabaseError {
2828
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
2929
XCTAssertEqual(error.message, """
30-
The database view 'items' has no primary key. \
31-
To support views, provide a custom schema source \
32-
in Configuration.schemaSource.
30+
database view items has no primary key
3331
""")
3432
XCTAssertEqual(error.description, """
35-
SQLite error 1: The database view 'items' has no primary key. \
36-
To support views, provide a custom schema source \
37-
in Configuration.schemaSource.
33+
SQLite error 1: database view items has no primary key
3834
""")
3935
}
4036
}
@@ -282,12 +278,10 @@ class PrimaryKeyInfoTests: GRDBTestCase {
282278
} catch let error as DatabaseError {
283279
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
284280
XCTAssertEqual(error.message, """
285-
The database view 'playerView' has no primary key, \
286-
according to Configuration.schemaSource.
281+
database view playerView has no primary key
287282
""")
288283
XCTAssertEqual(error.description, """
289-
SQLite error 1: The database view 'playerView' has no primary key, \
290-
according to Configuration.schemaSource.
284+
SQLite error 1: database view playerView has no primary key
291285
""")
292286
}
293287
}
@@ -322,12 +316,10 @@ class PrimaryKeyInfoTests: GRDBTestCase {
322316
} catch let error as DatabaseError {
323317
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
324318
XCTAssertEqual(error.message, """
325-
The database view 'playerView' has no primary key, \
326-
according to Configuration.schemaSource.
319+
database view playerView has no primary key
327320
""")
328321
XCTAssertEqual(error.description, """
329-
SQLite error 1: The database view 'playerView' has no primary key, \
330-
according to Configuration.schemaSource.
322+
SQLite error 1: database view playerView has no primary key
331323
""")
332324
}
333325
}

0 commit comments

Comments
 (0)