You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A more useful error from decodeAccumulating could look like this:
Invalid(NonEmptyList(DecodingFailure at .i: Int, DecodingFailure at .s: Missing required field, DecodingFailure at .c: Missing required field, DecodingFailure at .values: Missing required field))
It looks like this could be accomplished with a change to Decoder#or (and likely a similar change to Decoder#either, for consistency):
// ExistingoverridedeftryDecodeAccumulating(c: ACursor):Decoder.AccumulatingResult[AA] =
self.tryDecodeAccumulating(c) match {
case r @Valid(_) => r
caseInvalid(_) => d.tryDecodeAccumulating(c)
}
// ProposedoverridedeftryDecodeAccumulating(c: ACursor):Decoder.AccumulatingResult[AA] =
self.tryDecodeAccumulating(c) match {
case r @Valid(_) => r
caseInvalid(i) => d.tryDecodeAccumulating(c).leftMap(i.concatNel)
}
The microsite shows the standard way to write a
Decoder
for an ADT is to merge a list ofDecoder
s usingDecoder#or
:This works when the JSON is correct, and produces misleading errors when the JSON structure is incorrect:
Which makes sense, as
decode
returns as single error. What makes less sense is thatdecodeAccumulating
returns almost exactly the same thing:A more useful error from
decodeAccumulating
could look like this:It looks like this could be accomplished with a change to
Decoder#or
(and likely a similar change toDecoder#either
, for consistency):Scastie with the above implemented as a Semigroup
The text was updated successfully, but these errors were encountered: