Recursion related exception: Unable to get property 'tag' of undefined or null reference

天涯浪子 提交于 2019-12-11 12:58:51

问题


I receive the following error after performing an HTTP post:

Unable to get property 'tag' of undefined or null reference

I believe the error occurs when executing the following decoder function:

sourceDecoder : Decoder JsonSource
sourceDecoder =
    Decode.map5 JsonSource
        ...
        (field "Links" providerLinksDecoder)

Decoder Dependencies:

providerLinksDecoder : Decoder JsonProviderLinks
providerLinksDecoder =
    Decode.map JsonLinkFields
        (field "Links" <| Decode.list (Decode.lazy (\_ -> linkDecoder)))
        |> Decode.map JsonProviderLinks

linkDecoder : Decoder JsonLink
linkDecoder =
    Decode.map6 JsonLink
        (field "Profile" profileDecoder)
        ...

profileDecoder : Decoder JsonProfile
profileDecoder =
    Decode.map7 JsonProfile
        ...
        (field "Sources" <| Decode.list (Decode.lazy (\_ -> sourceDecoder)))

Appendix:

type JsonProviderLinks
    = JsonProviderLinks JsonLinkFields


type alias JsonLinkFields =
    { links : List JsonLink
    }

The source code can be found on here.

Note: I attempted to research this error and came across this page. As a result, I attempted to use the Decode.lazy function. However, my attempt failed.


回答1:


There's a lot of decoders that rely on other decoders in your examples. You've changed some of them to use Decode.lazy, but not all, and that error you've received will happen when there's some out of control recursion.

You don't need a list to be able to use lazy. Try - as a first step towards debugging, at least - to change all decoders that reference other decoders to use Decode.lazy. For example:

sourceDecoder : Decoder JsonSource
sourceDecoder =
    Decode.map5 JsonSource
        ...
        (field "Links" (Decode.lazy (\_ -> providerLinksDecoder)))


来源:https://stackoverflow.com/questions/46821111/recursion-related-exception-unable-to-get-property-tag-of-undefined-or-null-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!