Skip to content

Commit

Permalink
Fix force unwrap in PostgresDataDecoder (#184)
Browse files Browse the repository at this point in the history
* Replace the force unwrap to throws

Things crash in here

* missing return
  • Loading branch information
SusanDoggie authored May 1, 2020
1 parent 152f69b commit e43a32b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/PostgresKit/PostgresDataDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ public final class PostgresDataDecoder {

func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
if let convertible = T.self as? PostgresDataConvertible.Type {
return convertible.init(postgresData: self.data)! as! T
guard let value = convertible.init(postgresData: data) else {
throw DecodingError.typeMismatch(T.self, DecodingError.Context.init(
codingPath: [],
debugDescription: "Could not convert to \(T.self): \(data)"
))
}
return value as! T
} else {
return try T.init(from: _Decoder(data: self.data, json: self.json))
}
Expand Down

0 comments on commit e43a32b

Please sign in to comment.