Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the role of DecodingFailure's "message" #306

Closed
travisbrown opened this issue Jun 19, 2016 · 5 comments
Closed

Clarify the role of DecodingFailure's "message" #306

travisbrown opened this issue Jun 19, 2016 · 5 comments

Comments

@travisbrown
Copy link
Member

circe's DecodingFailure is a descendant of Argonaut's (String, CursorHistory) in DecodeResult, and in Argonaut there's some ambiguity about what the string represents—in some places it's just a string representation of the type, and in other places it's a more detailed message about what went wrong. Since it doesn't have a name in Argonaut (and the corresponding argument to e.g. DecodeResult.fail is just named s), the library doesn't seem to make any particular commitment to how the string should be interpreted.

I originally planned to provide more guidance here in circe, but we're at version 0.5 and message in DecodingFailure is still playing both roles, and now the new DecodingFailure.fromThrowable in #303 puts a printed stack trace in the message field, which introduces yet another kind of thing that it can do.

I'd be interested in any suggestions about how we can refine the fields in DecodingFailure to make it clear what each one should do. One straightforward approach would be just to add new fields: something like name: String, message: String, an optional underlying: Option[Throwable], and the lazy CursorHistory, but I'm definitely open to other ideas.

@tomjadams
Copy link

Without knowing the particular piece of code overly well, your suggestions seem like a good first approach. Have you tried it and seen how the code pans out?

@liff
Copy link
Contributor

liff commented Nov 21, 2017

Just my €0.000002:

Personally, I'd be very much in favour of more descriptive error messages.

I think, compared to message being just the name of the type, The name, message, underlying triplet sounds very good. In particular, the stack trace in DecodingFailure.fromThrowable would make more sense as a separate field. Right now the failure messages from Decoder#emapTry are rather inconveniently messy :)

@jatcwang
Copy link
Contributor

jatcwang commented Mar 2, 2018

My preference is actual error classes representing common error cases. This gives the developers freedom to transform a decoding error into w/e output they need.

I think these should cover the common errors:

  • Missing Field
  • Incorrect Type (wrong JSON type)
  • Invalid data (e.g. constraint violation across multiple fields like start cannot be after end for a java.time.Period)

@fleipold
Copy link

While this is being pondered it would be nice to just use the Show instance added in #222 to produce the message. That way we would get the nice javascript-style path for the history which is much more usable for bigger documents.

@hamnis
Copy link
Collaborator

hamnis commented Jul 27, 2023

Closing in cleanup run, If anyone cares about this, please comment and I'll reopen.

@hamnis hamnis closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants