Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Fail instead of erroring for protobuf maps
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Dec 1, 2020
1 parent 38f2578 commit 67cc414
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions adapter/protobuf/src/Mu/Adapter/ProtoBuf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,16 @@ instance ( KnownNat (FindProtoBufId sch ty name)
where fieldId = fromInteger $ natVal (Proxy @(FindProtoBufId sch ty name))
go = PBDec.repeated (
PBDec.embedded'
((,) <$> PBDec.one protoToOneFieldValue
(error "key should always be present") `at` 1
<*> PBDec.one protoToOneFieldValue
(error "value should always be present") `at` 2))
((,) <$> fieldValueWithDefault 1
<*> fieldValueWithDefault 2))
`at` fieldId
fieldValueWithDefault innerFieldId
= case defaultOneFieldValue of
Nothing
-> do r <- PBDec.one (Just <$> protoToOneFieldValue) Nothing `at` innerFieldId
maybe empty pure r
Just d
-> PBDec.one protoToOneFieldValue d `at` innerFieldId <|> pure d

instance {-# OVERLAPS #-}
(ProtoBridgeUnionFieldValue (FindProtoBufOneOfIds sch ty name) sch ts)
Expand Down

0 comments on commit 67cc414

Please sign in to comment.