-
Notifications
You must be signed in to change notification settings - Fork 321
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
Custom error type #683
Comments
The best way forward is to implement your own I'm personally not against of having more structured |
Could it be possible to do make a more expressive data type data ResultE e a =
Error e |
Success a
type Result = ResultE String
data AesonError =
KeyMissing Text |
...
data Pointer = ...
-- like in http://hackage.haskell.org/package/aeson-diff-1.1.0.5/docs/Data-Aeson-Pointer.html
type DescrResult = ResultE [(Pointer, AesonError)]
Then write core functions in terms of That should be mostly backwards compatible, and provide better errors. |
@phadej Okay, that was the direction I was taking as well. I do understand our use case is quite specific. The way our API is designed means that all client input/output is done via JSON and we can have several clients (Web, Mobile), so having some structured errors becomes necessary. However, it seems to me that there is some dissatisfaction about error reporting about Aeson, and I'd be happy to contribute to that in any way. I do thinking having some custom error type, left to the discretion of the user, would be a good way forward. @kuribas Yes, something like that should work, I'm going to try and plug that in. What it still doesn't solve (correct me if I'm wrong) is accumulative errors. Our API clients prefer to have the backend throw all the errors at them so they can correct their inputs accordingly, in one go. |
@asheshambasta that's not possible with a monad instance. And the applicative |
Or you could make a newtype |
We're using Haskell to write one of our services, and we're using Aeson for input-json parsing.
However, the API of the platform as a whole must expose standardised validation errors like my example:
I see that in Aeson this is not possible, since the
Error
data constructor only usesString
for its output errors. Also, my understanding is that accumulating JSON errors is achieved using(<*>+)
which is quite cool.What I'd like to understand is how we achieve some sort of a custom error type that can be represented like the example above, if possible at all. The naive approach would be to use
fail
with some sort of standardized string and then parse the custom error fields out of it, but that is rather unsatisfactory.Is there a way to achieve this?
Edit: I'd like to contribute to this, but I'm quite new to Haskell.
The text was updated successfully, but these errors were encountered: