I wrote a script that handles my http get-requests. While testing (and deliberately creating http-errors, e.g. by disconnecting to the internet) the javascript sometimes crashes and the following error message is in the console:
Uncaught Error: Trying to use `(==)` on functions.
There is no way to know if functions are "the same" in the Elm sense.
Read more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.
at _Debug_crash (main.js:753)
at _Utils_eqHelp (main.js:106)
at _Utils_eqHelp (main.js:139)
at _Utils_eqHelp (main.js:139)
at _Utils_eq (main.js:88)
at Function.f (main.js:7427)
at A2 (main.js:56)
at main.js:8192
at $author$project$Main$behandelHttpQueue (main.js:8201)
at Function.f (main.js:12832)
_Debug_crash @ main.js:753
_Utils_eqHelp @ main.js:106
_Utils_eqHelp @ main.js:139
_Utils_eqHelp @ main.js:139
_Utils_eq @ main.js:88
(anonymous) @ main.js:7427
A2 @ main.js:56
(anonymous) @ main.js:8192
$author$project$Main$behandelHttpQueue @ main.js:8201
(anonymous) @ main.js:12832
A2 @ main.js:56
sendToApp @ main.js:1884
(anonymous) @ main.js:1994
_Scheduler_step @ main.js:1810
_Scheduler_enqueue @ main.js:1784
_Scheduler_rawSpawn @ main.js:1715
(anonymous) @ main.js:4585
setInterval (async)
(anonymous) @ main.js:4585
_Scheduler_step @ main.js:1810
_Scheduler_enqueue @ main.js:1784
_Scheduler_rawSpawn @ main.js:1715
handler @ main.js:4124
I cannot find the place where I misuse the (==) operator. Anyone any idea where to find the bug?
I’m guessing this is the issue. You are removing this item from the list based on if it equals any of the items in the list. But model.httpQueue probably contains functions that you can’t do equality testing on.
Http.Expect is a function that takes the response of the http request and converts it into a Msg so it isn’t equatable. What I recommend is that you have some id that you can store in httpQueue instead and use to reference the HttpRequest data.
Thanks a lot @MartinS
I didn’t realize that Http.Expect was a function, but I could have guessed it.
My solution is to remove the expect from the type alias HttpRequest. The type RequestData implies both the json-encoding and the expected response. When building the http command, I can get these based on the RequestData.