Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flatMap in jsonToBinaryBase64 #49

Conversation

lenguyenthanh
Copy link
Contributor

@lenguyenthanh lenguyenthanh commented Aug 24, 2024

This helps return better messaging in case of error.

Here are examples of (shorten) stack trace:

before:

[error] java.util.NoSuchElementException: None.get
[error]         at scala.None$.get(Option.scala:627)
[error]         at scala.None$.get(Option.scala:626)
[error]         at mongo4cats.circe.CirceJsonMapper$.jsonToBinaryBase64(CirceJsonMapper.scala:107)
[error]         at mongo4cats.circe.MongoJsonCodecs.$init$$

after:

[error] mongo4cats.errors$MongoJsonParsingException: DecodingFailure at ._id: "eCz830PN" is not a valid binary object
[error]         at mongo4cats.errors$MongoJsonParsingException$.apply(errors.scala:23)
[error]         at mongo4cats.circe.MongoJsonCodecs.mongo4cats$circe$MongoJsonCodecs$$anon$1$$_$get$$anonfun$2$$anonfun$1$$anonfun$1(MongoJsonCodecs.scala:99)
[error]         at scala.util.Either$LeftProjection.map(Either.scala:622)
[error]         at mongo4cats.circe.MongoJsonCodecs$$anon$1.get$$anonfun$2$$anonfun$1(MongoJsonCodecs.scala:99)
[error]         at scala.util.Either.flatMap(Either.scala:360)
[error]         at mongo4cats.circe.MongoJsonCodecs$$anon$1.get$$anonfun$2(MongoJsonCodecs.scala:99)

@Kirill5k Kirill5k merged commit aa99aa7 into Kirill5k:master Aug 25, 2024
3 checks passed
@lenguyenthanh lenguyenthanh deleted the better-error-message-for-circe-binary-parser branch August 25, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants