Pretty-printing of decoding failure history
See original GitHub issueFrom gitter: https://gitter.im/travisbrown/circe?at=56b1d0786b6468374a0b2b7c
Consider the following example:
scala> val json = parse("""[1, 2, "hello", 4, "world", 6]""").getOrElse(Json.empty)
scala> Decoder[List[Int]].apply(json.hcursor)
res5: io.circe.Decoder.Result[List[Int]] = Left(io.circe.DecodingFailure: Int: El(MoveRight,true),El(MoveRight,true),El(DownArray,true))
This part might be hard to parse for a human eye:
io.circe.DecodingFailure: Int: El(MoveRight,true),El(MoveRight,true),El(DownArray,true)
I guess we could improve the error message by reversing a history, making it a bit more visual, and maybe adding the element we failed to parse. Something along these lines:
[↴ array]
→|→ × Failed to decode hello as Int
I’m not sure about arrow symbols though (on github they are very tiny), so maybe just printing
[down array]
[right], [right] × Failed to decode hello as Int
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to resolve recursive decoding in Circe when parsing Json?
You can print the history like this (or just inspect it in the string ... DecodingFailure scala> io.circe.jawn.decode[Tasks](doc) match ...
Read more >json — JSON encoder and decoder — Python 3.11.1 ...
A malicious JSON string may cause the decoder to consume considerable CPU and memory ... Using json.tool from the shell to validate and...
Read more >circe/circe - Gitter
I'm trying to write a custom Decoder. Due to some unique 3rd party created constraints in the structure of the Json I'm getting,...
Read more >Pretty Printing JSON Web Tokens (JWTs) on the Command ...
How to easily introspect and pretty print a signed JWT (JWS) or an encrypted JWT (JWE) on the ... Printf("Error decoding string: %s...
Read more >JSON Decode Online - Code Beautify
What can you do with json_decode? · How to Create JSON File? · JSON Full Form · What is JSON? · JSON Example...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see that
CursorOp
already hasShow
instance defined, and string representations of operators are already pretty visual there.@tobias-johansson in his PR:
->
instead of[27]
, anddownField
from--\\(field)"
to.field
.These 2 things probably covers 80% of use-cases. For other Ops it just fallbacks to the already defined Show. Which gives us pretty much what I wanted to do minus a couple extra line-breaks 😃
@travisbrown do you think that going for the original output format is still relevant (comparing them side by side)?
From https://github.com/travisbrown/circe/pull/222#issuecomment-194017772,
looks really nice! What might be cool though is adding a current focus to the error message so it gives a bit more context
Quoting myself from Gitter:
So while #222 is merged, I think we should leave this issue open for the original more visual output proposed by @ArtemPyanykh.