mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Don't let JSONDecodingRequiredError go
JSON decoding: when row doesn't contain any Data, we don't want to expose a JSONDecodingRequiredError error to the user. We switch to a detailed conversion error instead (see #384).
This commit is contained in:
1 parent
275098084d
commit
aa8bc0fae3
1 file changed
+8
-10
@@ -89,12 +89,11 @@ private struct RowKeyedDecodingContainer<Key: CodingKey>: KeyedDecodingContainer
|
||||
// value here (string, int, double, data, null). If such an
|
||||
// error happens, we'll switch to JSON decoding.
|
||||
return try T(from: RowSingleValueDecoder(row: row, codingPath: codingPath + [key]))
|
||||
} catch let error as JSONDecodingRequiredError {
|
||||
if let data = row.dataNoCopy(atIndex: index) {
|
||||
return try JSONDecoder().decode(type.self, from: data)
|
||||
} else {
|
||||
throw error
|
||||
} catch is JSONDecodingRequiredError {
|
||||
guard let data = row.dataNoCopy(atIndex: index) else {
|
||||
fatalConversionError(to: T.self, from: row[index], conversionContext: ValueConversionContext(row).atColumn(index))
|
||||
}
|
||||
return try JSONDecoder().decode(type.self, from: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,12 +139,11 @@ private struct RowKeyedDecodingContainer<Key: CodingKey>: KeyedDecodingContainer
|
||||
// value here (string, int, double, data, null). If such an
|
||||
// error happens, we'll switch to JSON decoding.
|
||||
return try T(from: RowSingleValueDecoder(row: row, codingPath: codingPath + [key]))
|
||||
} catch let error as JSONDecodingRequiredError {
|
||||
if let data = row.dataNoCopy(atIndex: index) {
|
||||
return try JSONDecoder().decode(type.self, from: data)
|
||||
} else {
|
||||
throw error
|
||||
} catch is JSONDecodingRequiredError {
|
||||
guard let data = row.dataNoCopy(atIndex: index) else {
|
||||
fatalConversionError(to: T.self, from: row[index], conversionContext: ValueConversionContext(row).atColumn(index))
|
||||
}
|
||||
return try JSONDecoder().decode(type.self, from: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user