Skip to content

Commit

Permalink
Improve error message for int conversion
Browse files Browse the repository at this point in the history
This is taken from #15, credits to @nullbio.
  • Loading branch information
tiziano88 committed Sep 17, 2018
1 parent bf4da77 commit d06a9aa
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Protobuf.elm
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,21 @@ fromResult v =

{-| Turns a Maybe in to a Decoder
-}
fromMaybe : Maybe a -> JD.Decoder a
fromMaybe v =
case v of
fromMaybe : String -> Maybe a -> JD.Decoder a
fromMaybe error maybe =
case maybe of
Just v1 ->
JD.succeed v1

Nothing ->
JD.fail "error"
JD.fail error


{-| Decodes an Int from either a string or numeric.
-}
intDecoder : JD.Decoder Int
intDecoder =
JD.oneOf [ JD.int, JD.string |> JD.andThen (String.toInt >> fromMaybe) ]
JD.oneOf [ JD.int, JD.string |> JD.andThen (String.toInt >> fromMaybe "could not convert string to integer") ]


{-| Encodes an Int as a JSON string, for emitting to int64 proto3 fields
Expand Down

0 comments on commit d06a9aa

Please sign in to comment.