Hey Jacob,

Any update on this topic? I am facing the same issue, even in Elm 0.17 with 
latest libraries...

On Tuesday, November 3, 2015 at 11:16:53 PM UTC+1, Jacob Matthews wrote:
>
>
> I've been playing with Elm recently. I really like it in general, but I 
> have had some pretty frustrating experiences debugging Json.Decode.Decoder 
> failures, especially while handling browser events using Html.Events.on.
>
> For instance, suppose we want to write a decoder that reads the selected 
> index within a <select> element. We might write:
>
> import Json.Decode exposing (..)
>
> ...
>
> decodeSelectedIndex : Decoder string
> decodeSelectedIndex = at ["action", "selectedIndex"] string  -- oops! 
> selectedIndex is an int!
>
> renderSelect : Html
> renderSelect = 
>   select 
>     [ on "change" decodeSelectedIndex someHandler ]
>     [ ... ]
>   
> The problem here is that the decoder doesn't match the value being parsed, 
> but we can't figure out any way to either observe the raw value 
> pre-decoding (using Debug.watch, Debug.log or even a javascript 
> breakpoint) or to convince Html.Events.on to report an error if parsing 
> fails -- the handler just doesn't fires, with no indication of why.
>
> I tried creating a monitoring function 
>
> monitorDecoder : Decoder a -> Decoder a
> monitorDecoder decoder = 
>   customDecoder Json.Decode.value <| \value -> decodeValue decoder 
> (Debug.watch "decoding value" value)
>
> so that I could write 
>
>    on "change" (monitorDecoder decodeSelectedIndex) someHandler
>
> but that approach always fails to decode before the watch gets evaluated 
> -- I'm not sure why, but I suspect it's because the decoder is being asked 
> to decode a JavaScript event, which is not JSON-serializable, and thus the 
> Json.Decode.value decoder fails before the custom decoding logic runs at 
> all.
>
> Are there other strategies I can try? What do people normally do to write 
> solid decoders? I really like Elm in general but I'm worried about not 
> having an effective way to debug these kinds of issues.
>
> Thanks,
> -jacob
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to