Skip to content

Commit

Permalink
Handle uuid decoding failure
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpdaniels committed Jul 20, 2021
1 parent f6774c8 commit 01da641
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import zio.stream.ZTransducer
import zio.{ Chunk, ZIO }

import java.util.UUID
import scala.util.control.NonFatal

object ProtobufCodec extends Codec {
override def encoder[A](schema: Schema[A]): ZTransducer[Any, Nothing, A, Byte] =
Expand Down Expand Up @@ -590,7 +591,13 @@ object ProtobufCodec extends Codec {
case StandardType.DoubleType => doubleDecoder
case StandardType.BinaryType => binaryDecoder
case StandardType.CharType => stringDecoder.map(_.charAt(0))
case StandardType.UUIDType => stringDecoder.map(UUID.fromString)
case StandardType.UUIDType =>
stringDecoder.flatMap { uuid =>
try succeed(UUID.fromString(uuid))
catch {
case NonFatal(_) => fail("Invalid UUID string")
}
}
case StandardType.DayOfWeekType =>
varIntDecoder.map(_.intValue).map(DayOfWeek.of)
case StandardType.Month =>
Expand Down

0 comments on commit 01da641

Please sign in to comment.