Comments (6)
I see that CursorOp
already has Show
instance defined, and string representations of operators are already pretty visual there.
@tobias-johansson in his PR:
- collapsed array traversals which is very reasonable since you hardly ever want to see 27 arrows on the screen
->
instead of[27]
, and - changed the repr. of
downField
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)?
[↴ array]
→|→|→|→|→|→|→|→|→|→|→|→ × Int
// and
Decoding Failure at [12]: Int
From #222 (comment),
DecodingFailure at .bar.baz.qux.a: String
looks really nice! What might be cool though is adding a current focus to the error message so it gives a bit more context
DecodingFailure at .bar.baz.qux.a: decoding 10 as String
from circe.
I can take a look into it in a couple weeks after I get back from vacation.
from circe.
👍, this sounds great.
from circe.
From gitter: https://gitter.im/travisbrown/circe?at=56d079f2d2637aec24d4ccd8
WIP
I've done some work on a Show[DecodingFailure]
that tries to make simple, compact messages by representing the cursor history as javascript style selection, i.e. "DecodingFailure at .foo.bar[2].baz: some message"
.
I believe this is a good idea if you want to return error messages to http clients, etc.
WIP can be seen here: master...tobias-johansson:Show-DecodingFailure
It deals with normal navigation operations, and if there are other kinds of operations it falls back to Show[CursorOp]
for those.
Problem
The error messages could still be improved though, and I would like to discuss if it's possible to encode the reason for failure in DecodingFailure
s in a better way.
At the moment if I do
scala> decode[Int](""""a"""")
res8: cats.data.Xor[io.circe.Error,Int] = Left(io.circe.DecodingFailure: Int)
the message in the DecodingFailure
is simply the string "Int"
which isn't of much help when trying to create a nice error message.
Suggestion
I'm suggesting an explicit encoding of the reason to replace or complement the message
field in DecodingFailure
, something like:
sealed trait Reason
case class TypeExpectation(expected: String) extends Reason
case class FailedValidation(message: String) extends Reason
case object FailedCursor extends Reason
This would make it easy to create or customize error messages, or otherwise interpret failures, without the need to embed the full messages in Decoder
etc.
The downside might be that DecodingFailure
is public api along with some other things like Decoder[A].withErrorMessage
and I'm not sure how to deal with that.
What do you think?
from circe.
@tobias-johansson nice! I had similar idea in regard to implementation, but the JS-selection-like output scales better.
from circe.
Quoting myself from Gitter:
@tobias-johansson That sounds like reasonable output for
Show[DecodingFailure]
. I think it'd make sense to have the visualization that @artempyanykh describes in #188 be available as something like a draw method onDecodingFailure
, while theShow
instance gives the more compact representation you describe.
So while #222 is merged, I think we should leave this issue open for the original more visual output proposed by @artempyanykh.
from circe.
Related Issues (20)
- Support semiauto derivation without recursive derivation HOT 6
- Cannot derive `Decoder` for case class with inserction type fields HOT 1
- `BiggerDecimal.parseBiggerDecimalUnsafe` throws `NumberFormatException` HOT 1
- Bad encoding of Option in scala 2.12 HOT 1
- Decoding compilation fails for tagged types with Circe > 0.14.3 HOT 3
- Derivation doens't apply Configuration HOT 4
- Support new configuration that handles digit as a delimiter when converting to snake_case HOT 1
- How do I map a particular key and value in a custom way? HOT 2
- io.circe.pointer.literal.PointerInterpolatorSuite seems Flaky (or there's a bug?) HOT 2
- Maximal number of successive inlines (32) exceeded, Maybe this is caused by a recursive inline method? HOT 7
- Circe cannot decode output from auto-derived codec on Scala 3 HOT 1
- Scala3 derivation incorrectly assumes collection type for generic class HOT 4
- Stack overflow on 0.14.6 HOT 4
- Unexpected derivation of Encoder[Option[T]]
- Modifying JsonObject using ACursor/HCursor performance hit due to megamorphic calls HOT 1
- Invalid Json tree with `null` (java) values, NPE in printer HOT 1
- a problem with current derivations HOT 7
- Properly parse JSON object key with quotes HOT 1
- usage of ISO_ZONED_DATE_TIME as default formatter in encoder HOT 3
- Scala 2.13: derivedConfiguratedEncoder becomes unconfigured under some conditions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from circe.