We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 152f69b commit e43a32bCopy full SHA for e43a32b
Sources/PostgresKit/PostgresDataDecoder.swift
@@ -139,7 +139,13 @@ public final class PostgresDataDecoder {
139
140
func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
141
if let convertible = T.self as? PostgresDataConvertible.Type {
142
- return convertible.init(postgresData: self.data)! as! T
+ guard let value = convertible.init(postgresData: data) else {
143
+ throw DecodingError.typeMismatch(T.self, DecodingError.Context.init(
144
+ codingPath: [],
145
+ debugDescription: "Could not convert to \(T.self): \(data)"
146
+ ))
147
+ }
148
+ return value as! T
149
} else {
150
return try T.init(from: _Decoder(data: self.data, json: self.json))
151
}
0 commit comments