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
We have some codecs which bootstrap the String codec and convert values to our own internal enumeratum values.
The schema models the data as string or null, which we attempt to model as Option[OurEnumType].
The decoding works fine, except when an unexpected String comes through. The error message presented is Exhausted alternatives for type org.apache.avro.util.Utf8 - rather than the underlying failure with our custom message.
Broadly our codec looks a bit like the following:
caseclassMyThing(value: String)
objectMyThing {
deffromString(s: String):Option[MyThing] =if (s=="thing") Some(MyThing(s)) elseNoneimplicitvalcodec:Codec[MyThing] =Codec.string.imapError(str => fromString(str).toRight(AvroError(s"$str is not what we want")))(_.value)
}
Is there a way to make the underlying error message bubble up? This issue led to a bit of head scratching because the stack trace didn't identify where the problem was either.
The text was updated successfully, but these errors were encountered:
I managed to get something which emits the correct error message with the following, but it would be nice to have something in the API to support this, similar to how Circe works
implicitvalmyThingCodec:Codec[Option[MyThing]] =Codec
.option[String]
.imapError[Option[MyThing]] ({
caseSome(str) => fromString(str).map(Some(_)).toRight(AvroError(s"$str not what we want"))
caseNone=>Right(None)
})(maybeMyThing => maybeMyThing.map(myThing => myThing.value))
This is really a special case of a more general issue, which is that union decoders don't propagate specific errors when all alternatives fail. It could be nice to expose the reason why each alternative failed.
That said, even if we don't do that it might also be worth special-casing the Option codec so that it reports the underlying error when failing to decode a non-null value.
We have some codecs which bootstrap the String codec and convert values to our own internal enumeratum values.
The schema models the data as string or null, which we attempt to model as
Option[OurEnumType]
.The decoding works fine, except when an unexpected String comes through. The error message presented is
Exhausted alternatives for type org.apache.avro.util.Utf8
- rather than the underlying failure with our custom message.Broadly our codec looks a bit like the following:
Is there a way to make the underlying error message bubble up? This issue led to a bit of head scratching because the stack trace didn't identify where the problem was either.
The text was updated successfully, but these errors were encountered: