question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow customization of the error message for missing element when decoding

See original GitHub issue

Currently decoding a JSON that misses an element will result in a DecodingFailure with a message saying: "Attempt to decode value on failed cursor". This error cannot be customized other than by doing string matching on DecodingFailure.message. I would suggest to add a default parameter on decode and decodeAccumulating:

final def decode[A: Decoder](input: String, missingElementErrorMessage: String =
                             defaultMissingElementErrorMessage)

An alternative would be to encode that case in the type:

sealed trait DecodingFailure { def history: List[CursorOp] }
case class MissingElement(val history: List[CursorOp]) extends DecodingFailure
case class IncorrectValue( /* ... */ ) extends DecodingFailure

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:16
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
exoegocommented, May 30, 2019

I opended a PR #1081 to implement this feature, but no response for 3 months. If it is unlikely to be implemented in circe, please close this issue as wontfix.

1reaction
knutwalkercommented, Mar 14, 2017

Maybe this might help; I did change the message by looking at the cursor history and trying to examine whether the failure was due to a missing field (which could be simplified a bit by using CursorOp.opsToPath): https://github.com/knutwalker/akka-stream-json/blob/b8bc752ef3ab2f76793c0db40bddc8a2bd5787df/support/stream-circe/src/main/scala/de/knutwalker/akka/stream/support/CirceStreamSupport.scala#L46-L73

Read more comments on GitHub >

github_iconTop Results From Across the Web

"The data couldn't be read because it is missing" error when ...
The data couldn't be read because it is missing. When I run the following code: struct Indicator: Decodable { let section: String ...
Read more >
Get Started with Custom Error Handling in Spring Boot (Java)
Learn how to implement custom error handling logic in Spring Boot. You will see two approaches based on the @ControllerAdvice annotation.
Read more >
Ignoring invalid JSON elements when using Codable
How elements containing missing or invalid data can be automatically ignored when using Swift's Codable API to parse JSON.
Read more >
Decode an array with a corrupted element - Sarunw
Each User required first name and last name; the middle name is optional. struct User: Codable { let firstName: String
Read more >
Codable: Tips and Tricks | kean.blog
struct Post: Decodable { let id: Id<Post> // More about this type ... Swift provides a complete error report using DecodingError which is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found