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

Json.Decode.customDecoder swallows Err strings #637

Closed
noahzgordon opened this Issue Jun 3, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@noahzgordon
Contributor

noahzgordon commented Jun 3, 2016

The function Json.Decode.customDecoder has the following type:

Decoder a -> (a -> Result String b) -> Decoder b

My expectation as a user is that the decoder produced by customDecoder decodes an initial payload using the first argument, then maps the result into the second argument. However, when the second argument is applied and its result resolves to an Err string, the string is discarded. No matter what, when a custom decoder fails, the string value of Err is "Expecting something custom but instead got: ".

You can reproduce this by entering the following into elm repl:

import Json.Decode exposing (customDecoder, decodeString, string, (:=))

jsonString = """{ "foo": "bar" }"""

myDecoder = customDecoder ("foo" := string) (\_ -> Err "I want to see this message!")

decodeString myDecoder jsonString
-- Err "Expecting something custom but instead got: {\"foo\":\"bar\"}"
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 15, 2016

Member

Should be fixed by in 7f6e518

Member

evancz commented Jul 15, 2016

Should be fixed by in 7f6e518

@evancz evancz closed this Jul 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment