I know I'm kind of late to the party here, but I was having this same
problem, so I wrote some code to log the error message:
traceDecoder : String -> JD.Decoder msg -> JD.Decoder msg
traceDecoder message decoder =
JD.value `JD.andThen` \value ->
case JD.decodeValue decoder value of
Ok decoded ->
JD.succeed decoded
Err err ->
JD.fail <| Debug.log message <| err
Then you wrap your decoder in the trace function, e.g.
on "mousedown" (traceDecoder myDecoder)
Worked well for me.
HTH,
Chris Baker
On Saturday, August 20, 2016 at 9:10:30 AM UTC-7, Sergey Zubtsovskiy wrote:
>
> Thank you for explanation! I should give it a try.
>
> Sergey Zubtsovskiy
> [email protected] <javascript:>
> Skype: szubtsovskiy
>
>
> 2016-08-19 23:06 GMT+02:00 OvermindDL1 <[email protected] <javascript:>>:
>
>> Given this:
>> ```elm
>> onScroll tagger =
>> on "scroll" (Json.Decode.map tagger decodeScrollPosition)
>> ```
>> If you *always* want it to be called, and since we know in this case that
>> the scroll javascript event will not return a negative number then you
>> could do this for decodeScrollPosition:
>> ```elm
>> decodeScrollPosition =
>> Json.Decode.oneOf
>> [ Json.Decoder.int
>> , Json.Decoder.succeed -1
>> ]
>> ```
>>
>> Or you could parse out a `Maybe Int`, or you could parse out a structure
>> if you want a more stuff. Etc... :-)
>>
>>
>> On Friday, August 19, 2016 at 2:45:32 PM UTC-6, Sergey Zubtsovskiy wrote:
>>>
>>> I am not sure I understand the answer. If you are talking about calling
>>> decode function then, as Jacob mentioned, it works in all cases but the one
>>> we're wondering about.
>>>
>>> Check this example:
>>>
>>> onScroll tagger =
>>>> on "scroll" (Json.Decode.map tagger decodeScrollPosition)
>>>
>>>
>>> Where decodeScrollPosition is:
>>>
>>>> decodeScrollPosition : Json.Decode.Decoder Int
>>>
>>>
>>> "on" function is only accepting value of type Json.Decode.Decoder. If I
>>> was decoding myself (e.g. by calling Json.Decode.decodeString) I would get
>>> a Result and process it the way you mention. But in case of an event
>>> listener decoding is happening somewhere within Elm runtime which silently
>>> swallows error. If I, for example, misspell event's field name, nothing
>>> will happen. No runtime error (that's still valid), but no result either.
>>>
>>> I am wondering if I am missing something. To my mind it does not fit to
>>> the whole impression Elm's trying to create. And I am a bit confused.
>>>
>>> Sergey Zubtsovskiy
>>> [email protected]
>>> Skype: szubtsovskiy
>>>
>>>
>>> 2016-08-19 21:31 GMT+02:00 Simon <[email protected]>:
>>>
>>>> <shamless-plug>
>>>> My emulator may help - http://simonh1000.github.io/decoder/
>>>> </shamless-plug>
>>>>
>>>> On Friday, 19 August 2016 19:56:05 UTC+2, OvermindDL1 wrote:
>>>>
>>>> On Friday, August 19, 2016 at 11:17:45 AM UTC-6, Sergey Zubtsovskiy
>>>>> wrote:
>>>>>>
>>>>>> Hey Jacob,
>>>>>>
>>>>>> Any update on this topic? I am facing the same issue, even in Elm
>>>>>> 0.17 with latest libraries...
>>>>>>
>>>>>
>>>>> You can setup multiple branches in a decode so it one fails then you
>>>>> can fall back to a default value so it still passes. You could even
>>>>> return
>>>>> a Maybe and return a default value of Nothing if you want, wrapping the
>>>>> main decode branch in a Just.
>>>>>
>>>>
>>>>
>>>> --
>>>> 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 [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>> 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 [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.