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.

Error messages lost for recusive decoders

See original GitHub issue

When using emap to create a custom validation for a recusive decoder the error messages are lost for the parts of the object which are decoded recursively:

import io.circe._, io.circe.generic.semiauto._, io.circe.generic.decoding.DerivedDecoder, io.circe.generic.encoding.DerivedObjectEncoder

case class A(i: Int, l: List[A])

def validA(a: A): Boolean = {
    a.i > 0 && a.l.map(validA).foldLeft(true)(_ && _)
}

implicit val ae: Decoder[A] = deriveDecoder[A].emap { a =>
    if(!validA(a)) {
        Left("Bad!")
    } else {
        Right(a)
    }
}

val s = """{"i":1, "l": [{"i": -1, "l": []}, {"i": 2, "l": []}]}"""

parser.parse(s).right.get.as[A]

When running the last line of code you get

io.circe.Decoder.Result[A] = Left(DecodingFailure([A]List[A], List(DownArray, DownField(l))))

Which is a valid decoding failure, but the error message of [A]List[A] isn’t what is expected. I would expect Bad! or something similar to DecodingFailure at .l[0]: Bad!

I’m using circe 0.7.0 for reference. And this issue was originally raised in the gitter channel

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
cponomaryovcommented, Jun 1, 2017
0reactions
travisbrowncommented, Jun 1, 2017

@EdgeCaseBerg Normally I’ve been closing issues when the fix hits master. If it’s really urgent I could backport this for an 0.8.1, but I’m guessing 0.9 is less than a week off and I wouldn’t be able to get 0.8.1 out until Saturday anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recursive decoding and its performance for low-rate Reed ...
error weights for which the decoding error probability vanishes on the entire sequence of decoding steps as the code length grows.
Read more >
Recursive List Decoding for Reed-Muller Codes and ... - arXiv
Abstract. We consider recursive decoding for Reed-Muller (RM) codes and their subcodes. Two new recursive techniques are described.
Read more >
Compiler error for recursive decoder using glennsl/rescript ...
I've run into a compiler error I think I need some help with while trying to create a recursive decoder using ...
Read more >
Decoding recursive JSON in Elm - Korban.net
In this post, I'd like to tell the story of implementing recursive decoders. The path to a recursive decoder. The basic structure of...
Read more >
Recursive List Decoding for Reed-Muller Codes and Their ...
We consider recursive decoding for Reed-Muller (RM) codes and their subcodes. Two new recursive techniques are described. We analyze asymptotic properties ...
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