Skip to content

Commit e43a32b

Browse files
authored
Fix force unwrap in PostgresDataDecoder (vapor#184)
* Replace the force unwrap to throws Things crash in here * missing return
1 parent 152f69b commit e43a32b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/PostgresKit/PostgresDataDecoder.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ public final class PostgresDataDecoder {
139139

140140
func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
141141
if let convertible = T.self as? PostgresDataConvertible.Type {
142-
return convertible.init(postgresData: self.data)! as! T
142+
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
143149
} else {
144150
return try T.init(from: _Decoder(data: self.data, json: self.json))
145151
}

0 commit comments

Comments
 (0)