Skip to content

Commit b572982

Browse files
committed
Document RowDecodingError
1 parent 5a8b025 commit b572982

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

GRDB/Core/Row.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ import Foundation
129129
///
130130
/// - ``RowAdapter``
131131
///
132+
/// ### Errors
133+
///
134+
/// - ``RowDecodingError``
135+
///
132136
/// ### Supporting Types
133137
///
134138
/// - ``RowCursor``

GRDB/Core/RowDecodingError.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ enum RowKey: Hashable, Sendable {
2424
}
2525

2626
/// A decoding error thrown when decoding a database row.
27+
///
28+
/// For example:
29+
///
30+
/// ```swift
31+
/// let row = try Row.fetchOne(db, sql: "SELECT NULL AS name")!
32+
/// // RowDecodingError: could not decode String from database value NULL.
33+
/// let name = try row.decode(String.self, forColumn: "name")
34+
/// ```
2735
public struct RowDecodingError: Error {
2836
enum Impl {
2937
case keyNotFound(RowKey, Context)

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4984,12 +4984,13 @@ try dbQueue.write { db in
49844984

49854985
## Error Handling
49864986

4987-
GRDB can throw [DatabaseError](#databaseerror), [RecordError], or crash your program with a [fatal error](#fatal-errors).
4987+
GRDB can throw [DatabaseError](#databaseerror), [RecordError], [RowDecodingError], or crash your program with a [fatal error](#fatal-errors).
49884988

49894989
Considering that a local database is not some JSON loaded from a remote server, GRDB focuses on **trusted databases**. Dealing with [untrusted databases](#how-to-deal-with-untrusted-inputs) requires extra care.
49904990

49914991
- [DatabaseError](#databaseerror)
49924992
- [RecordError]
4993+
- [RowDecodingError]
49934994
- [Fatal Errors](#fatal-errors)
49944995
- [How to Deal with Untrusted Inputs](#how-to-deal-with-untrusted-inputs)
49954996
- [Error Log](#error-log)
@@ -5094,6 +5095,18 @@ do {
50945095
```
50955096

50965097

5098+
### RowDecodingError
5099+
5100+
📖 [`RowDecodingError`](https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/rowdecodingerror)
5101+
5102+
**RowDecodingError** is thrown when the application can not decode a value from a database row. For example:
5103+
5104+
```swift
5105+
let row = try Row.fetchOne(db, sql: "SELECT NULL AS name")!
5106+
// RowDecodingError: could not decode String from database value NULL.
5107+
let name = try row.decode(String.self, forColumn: "name")
5108+
```
5109+
50975110
### Fatal Errors
50985111

50995112
**Fatal errors notify that the program, or the database, has to be changed.**
@@ -6111,6 +6124,7 @@ This chapter has been superseded by [ValueObservation] and [DatabaseRegionObserv
61116124
[persistence methods]: #persistence-methods
61126125
[Persistence Methods and the `RETURNING` clause]: #persistence-methods-and-the-returning-clause
61136126
[RecordError]: #recorderror
6127+
[RowDecodingError]: #rowdecodingerror
61146128
[Transactions and Savepoints]: https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/transactions
61156129
[`DatabaseQueue`]: https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/databasequeue
61166130
[Database queues]: https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/databasequeue

0 commit comments

Comments
 (0)