mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Hide implementation of RowDecodingError
Turn the enum into a struct so that it can be made public without exposing internal details
This commit is contained in:
1 parent
3f928bcf9c
commit
ad704c58e5
5 files changed
+102
-76
No files matched your search
@@ -25,7 +25,12 @@ enum RowKey: Hashable, Sendable {
|
||||
|
||||
/// A decoding error
|
||||
@usableFromInline
|
||||
enum RowDecodingError: Error {
|
||||
struct RowDecodingError: Error {
|
||||
enum Impl {
|
||||
case keyNotFound(RowKey, Context)
|
||||
case valueMismatch(Any.Type, Context)
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
struct Context: CustomDebugStringConvertible, Sendable {
|
||||
/// A description of what went wrong, for debugging purposes.
|
||||
@@ -55,17 +60,19 @@ enum RowDecodingError: Error {
|
||||
}
|
||||
}
|
||||
|
||||
case keyNotFound(RowKey, Context)
|
||||
case valueMismatch(Any.Type, Context)
|
||||
|
||||
var impl: Impl
|
||||
var context: Context {
|
||||
switch self {
|
||||
switch impl {
|
||||
case .keyNotFound(_, let context),
|
||||
.valueMismatch(_, let context):
|
||||
return context
|
||||
}
|
||||
}
|
||||
|
||||
static func valueMismatch(_ type: Any.Type, _ context: Context) -> Self {
|
||||
self.init(impl: .valueMismatch(type, context))
|
||||
}
|
||||
|
||||
/// Convenience method that builds the
|
||||
/// `could not decode <Type> from database value <value>` error message.
|
||||
static func valueMismatch(
|
||||
@@ -74,11 +81,10 @@ enum RowDecodingError: Error {
|
||||
databaseValue: DatabaseValue)
|
||||
-> Self
|
||||
{
|
||||
valueMismatch(
|
||||
type,
|
||||
RowDecodingError.Context(decodingContext: context, debugDescription: """
|
||||
could not decode \(type) from database value \(databaseValue)
|
||||
"""))
|
||||
let context = RowDecodingError.Context(decodingContext: context, debugDescription: """
|
||||
could not decode \(type) from database value \(databaseValue)
|
||||
""")
|
||||
return self.init(impl: .valueMismatch(type, context))
|
||||
}
|
||||
|
||||
/// Convenience method that builds the
|
||||
@@ -115,11 +121,15 @@ enum RowDecodingError: Error {
|
||||
/// error message.
|
||||
@usableFromInline
|
||||
static func columnNotFound(_ columnName: String, context: RowDecodingContext) -> Self {
|
||||
keyNotFound(
|
||||
self.init(impl: .keyNotFound(
|
||||
.columnName(columnName),
|
||||
RowDecodingError.Context(decodingContext: context, debugDescription: """
|
||||
column not found: \(String(reflecting: columnName))
|
||||
"""))
|
||||
""")))
|
||||
}
|
||||
|
||||
static func keyNotFound(_ rowKey: RowKey, _ context: Context) -> Self {
|
||||
self.init(impl: .keyNotFound(rowKey, context))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ extension DatabaseDataDecodingStrategyTests {
|
||||
XCTFail("Unexpected Data")
|
||||
}
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Data from database value "invalid" - \
|
||||
|
||||
@@ -208,7 +208,7 @@ extension DatabaseDateDecodingStrategyTests {
|
||||
XCTFail("Unexpected Date")
|
||||
}
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value "Yesterday" - \
|
||||
@@ -254,7 +254,7 @@ extension DatabaseDateDecodingStrategyTests {
|
||||
} catch let error as RowDecodingError {
|
||||
// Decoding from DatabaseValue does not work:
|
||||
// "Yesterday" is not decoded as 0.
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value "Yesterday" - \
|
||||
@@ -298,7 +298,7 @@ extension DatabaseDateDecodingStrategyTests {
|
||||
} catch let error as RowDecodingError {
|
||||
// Decoding from DatabaseValue does not work:
|
||||
// "Yesterday" is not decoded as 0.
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value "Yesterday" - \
|
||||
@@ -352,7 +352,7 @@ extension DatabaseDateDecodingStrategyTests {
|
||||
} catch let error as RowDecodingError {
|
||||
// Decoding from DatabaseValue does not work:
|
||||
// "Yesterday" is not decoded as 0.
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value "Yesterday" - \
|
||||
@@ -397,7 +397,7 @@ extension DatabaseDateDecodingStrategyTests {
|
||||
XCTFail("Unexpected Date")
|
||||
}
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value "Yesterday" - \
|
||||
@@ -443,7 +443,7 @@ extension DatabaseDateDecodingStrategyTests {
|
||||
XCTFail("Unexpected Date")
|
||||
}
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value "Yesterday" - \
|
||||
@@ -480,7 +480,7 @@ extension DatabaseDateDecodingStrategyTests {
|
||||
XCTFail("Unexpected Date")
|
||||
}
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value "invalid" - \
|
||||
|
||||
@@ -23,7 +23,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil])
|
||||
@@ -44,7 +44,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil])
|
||||
@@ -74,7 +74,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("name"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -94,7 +94,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("name"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -139,7 +139,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(1))
|
||||
XCTAssertEqual(context.row, ["1": 1, "value": "invalid"])
|
||||
@@ -160,7 +160,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(1))
|
||||
XCTAssertEqual(context.row, ["1": 1, "value": "invalid"])
|
||||
@@ -190,7 +190,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("value"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -210,7 +210,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("value"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -248,7 +248,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -269,7 +269,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -299,7 +299,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("name"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -319,7 +319,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("name"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -360,7 +360,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(1))
|
||||
XCTAssertEqual(context.row, ["name": nil, "value": "invalid"])
|
||||
@@ -381,7 +381,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(1))
|
||||
XCTAssertEqual(context.row, ["name": nil, "value": "invalid"])
|
||||
@@ -411,7 +411,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("value"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -431,7 +431,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("value"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -484,7 +484,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -521,7 +521,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record(row: row)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("value"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -541,7 +541,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Record.fetchOne(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("value"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -571,7 +571,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try String.fetchAll(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -595,7 +595,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try row.decode(String.self, forKey: "name")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -617,7 +617,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try row.decode(String.self, atIndex: 0)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -648,7 +648,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
.next()
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .keyNotFound(key, context):
|
||||
XCTAssertEqual(key, .columnName("missing"))
|
||||
XCTAssertEqual(context.key, nil)
|
||||
@@ -670,7 +670,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Int8.fetchAll(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["foo": 1000])
|
||||
@@ -694,7 +694,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try row.decode(Int8.self, forKey: "foo")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["foo": 1000])
|
||||
@@ -716,7 +716,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try row.decode(Int8.self, atIndex: 0)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["foo": 1000])
|
||||
@@ -749,7 +749,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Value.fetchAll(statement)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -772,7 +772,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try Value.fetchOne(statement, adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(1))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -796,7 +796,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try row.decode(Value.self, forKey: "name")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -818,7 +818,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try row.decode(Value.self, atIndex: 0)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["name": nil, "team": "invalid"])
|
||||
@@ -840,7 +840,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase {
|
||||
_ = try row.decode(Value.self, atIndex: 0)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case let .valueMismatch(_, context):
|
||||
XCTAssertEqual(context.key, .columnIndex(0))
|
||||
XCTAssertEqual(context.row, ["team": "invalid"])
|
||||
|
||||
@@ -376,7 +376,7 @@ extension FetchableRecordDecodableTests {
|
||||
_ = try StructWithData(row: ["data": nil])
|
||||
XCTFail("Expected Error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Data from database value NULL - \
|
||||
@@ -395,7 +395,7 @@ extension FetchableRecordDecodableTests {
|
||||
}
|
||||
XCTFail("Expected Error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Data from database value NULL - \
|
||||
@@ -439,7 +439,7 @@ extension FetchableRecordDecodableTests {
|
||||
_ = try StructWithDate(row: ["date": nil])
|
||||
XCTFail("Expected Error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value NULL - \
|
||||
@@ -458,7 +458,7 @@ extension FetchableRecordDecodableTests {
|
||||
}
|
||||
XCTFail("Expected Error")
|
||||
} catch let error as RowDecodingError {
|
||||
switch error {
|
||||
switch error.impl {
|
||||
case .valueMismatch:
|
||||
XCTAssertEqual(error.description, """
|
||||
could not decode Date from database value NULL - \
|
||||
@@ -1050,9 +1050,13 @@ extension FetchableRecordDecodableTests {
|
||||
"optionalDates2": "[128000]",
|
||||
])
|
||||
XCTFail("Expected error")
|
||||
} catch let RowDecodingError.keyNotFound(.columnName(column), context) {
|
||||
XCTAssertEqual(column, "requiredId")
|
||||
XCTAssertEqual(context.debugDescription, "column not found: \"requiredId\"")
|
||||
} catch let error as RowDecodingError {
|
||||
if case let .keyNotFound(.columnName(column), context) = error.impl {
|
||||
XCTAssertEqual(column, "requiredId")
|
||||
XCTAssertEqual(context.debugDescription, "column not found: \"requiredId\"")
|
||||
} else {
|
||||
XCTFail("Unexpected error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1163,12 +1167,16 @@ extension FetchableRecordDecodableTests {
|
||||
"optional_dates2": "[128000]",
|
||||
])
|
||||
XCTFail("Expected error")
|
||||
} catch let RowDecodingError.keyNotFound(.columnName(column), context) {
|
||||
XCTAssertEqual(column, "requiredId")
|
||||
XCTAssertEqual(context.debugDescription, """
|
||||
key not found: CodingKeys(stringValue: "requiredId", intValue: nil) ("requiredId"), \
|
||||
converted to required_id
|
||||
""")
|
||||
} catch let error as RowDecodingError {
|
||||
if case let .keyNotFound(.columnName(column), context) = error.impl {
|
||||
XCTAssertEqual(column, "requiredId")
|
||||
XCTAssertEqual(context.debugDescription, """
|
||||
key not found: CodingKeys(stringValue: "requiredId", intValue: nil) ("requiredId"), \
|
||||
converted to required_id
|
||||
""")
|
||||
} else {
|
||||
XCTFail("Unexpected error")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -1180,13 +1188,17 @@ extension FetchableRecordDecodableTests {
|
||||
"optional_dates2": "[128000]",
|
||||
])
|
||||
XCTFail("Expected error")
|
||||
} catch let RowDecodingError.keyNotFound(.columnName(column), context) {
|
||||
XCTAssertEqual(column, "requiredID")
|
||||
XCTAssertEqual(context.debugDescription, """
|
||||
key not found: CodingKeys(stringValue: "requiredID", intValue: nil) ("requiredID"), \
|
||||
with divergent representation requiredId, \
|
||||
converted to required_id
|
||||
""")
|
||||
} catch let error as RowDecodingError {
|
||||
if case let .keyNotFound(.columnName(column), context) = error.impl {
|
||||
XCTAssertEqual(column, "requiredID")
|
||||
XCTAssertEqual(context.debugDescription, """
|
||||
key not found: CodingKeys(stringValue: "requiredID", intValue: nil) ("requiredID"), \
|
||||
with divergent representation requiredId, \
|
||||
converted to required_id
|
||||
""")
|
||||
} else {
|
||||
XCTFail("Unexpected error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1264,11 +1276,15 @@ extension FetchableRecordDecodableTests {
|
||||
"_optionalDates2": "[128000]",
|
||||
])
|
||||
XCTFail("Expected error")
|
||||
} catch let RowDecodingError.keyNotFound(.columnName(column), context) {
|
||||
XCTAssertEqual(column, "requiredId")
|
||||
XCTAssertEqual(context.debugDescription, """
|
||||
key not found: CodingKeys(stringValue: "requiredId", intValue: nil) ("requiredId")
|
||||
""")
|
||||
} catch let error as RowDecodingError {
|
||||
if case let .keyNotFound(.columnName(column), context) = error.impl {
|
||||
XCTAssertEqual(column, "requiredId")
|
||||
XCTAssertEqual(context.debugDescription, """
|
||||
key not found: CodingKeys(stringValue: "requiredId", intValue: nil) ("requiredId")
|
||||
""")
|
||||
} else {
|
||||
XCTFail("Unexpected error")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user