GithubHelp home page GithubHelp logo

Comments (6)

artempyanykh avatar artempyanykh commented on July 22, 2024 2

I see that CursorOp already has Show instance defined, and string representations of operators are already pretty visual there.

@tobias-johansson in his PR:

  1. collapsed array traversals which is very reasonable since you hardly ever want to see 27 arrows on the screen -> instead of [27], and
  2. 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.

artempyanykh avatar artempyanykh commented on July 22, 2024

I can take a look into it in a couple weeks after I get back from vacation.

from circe.

travisbrown avatar travisbrown commented on July 22, 2024

👍, this sounds great.

from circe.

tobias-johansson avatar tobias-johansson commented on July 22, 2024

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 DecodingFailures 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.

artempyanykh avatar artempyanykh commented on July 22, 2024

@tobias-johansson nice! I had similar idea in regard to implementation, but the JS-selection-like output scales better.

from circe.

travisbrown avatar travisbrown commented on July 22, 2024

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 on DecodingFailure, while the Show 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.