与递归相关的异常:无法获取未定义或空引用的属性“标记” [英] Recursion related exception: Unable to get property 'tag' of undefined or null reference
问题描述
执行HTTP发布后,我收到以下错误消息:
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)
解码器依赖性:
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)))
附录:
type JsonProviderLinks
= JsonProviderLinks JsonLinkFields
type alias JsonLinkFields =
{ links : List JsonLink
}
源代码位于此处。
注意:我试图研究此错误,并遇到此页面。
结果,我尝试使用Decode.lazy函数。但是,我的尝试失败了。
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.
推荐答案
在您的示例中,有很多解码器依赖于其他解码器。您已经更改了其中一些使用 Decode.lazy
的功能,但不是全部,并且当某些不可控制的递归时,您会收到该错误。
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.
您不需要列表即可使用懒惰
。尝试-至少是调试的第一步-更改引用其他解码器的 all 解码器以使用 Decode.lazy
。例如:
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)))
这篇关于与递归相关的异常:无法获取未定义或空引用的属性“标记”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!