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:
Gwendal Roué committed 2018-08-15 10:24:28 +02:00
1 parent 275098084d
commit aa8bc0fae3
1 file changed
+8 -10
+8 -10
View File
@@ -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)
}
}
}