You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error: Trying to send an unexpected type of value through port `test`: [object Object]
Expected something like this:
Error: Trying to send an unexpected type of value through port `test`: Expected a STRING, but got: 1337
Story
If I have a port like this…
port test: (String->msg) ->Submsg
…and accidentally send a number instead of a string…
app.ports.test.send(1337)
…I get this error:
Error: Trying to send an unexpected type of value through port `test`: [object Object]
It seems like no matter what type of faulty value I send, it always says [object Object]. Which isn’t very helpful :)
The browser devtools shows not only the error message, but also which piece of code caused the error. If I click the error location, I’m taken to code looking like this in the devtools debugger:
case 4:
varportName=fact1;varproblem=fact2;thrownewError('Trying to send an unexpected type of value through port `'+portName+'`:\n'+problem);
That explains where [object Object] is coming from. So it looks like it would be possible to say something like Expecting a STRING, but got: 1337 instead.
Background
The other day I was trying to make a port like this:
port clickedOutsideDropdown: (()->msg) ->Submsg
The JavaScript code only has to tell Elm that a click occurred, but does not need to pass any extra information. That’s why I used unit/() in the port.
When it was time to implement the JavaScript part, I was thinking: “Since this port does not take any value, do I need to pass anything to .send?” So I tried this…
app.ports.clickedOutsideDropdown.send()
…which gave me this error:
Error: Trying to send an unexpected type of value through port `test`: [object Object]
I was confused. I didn’t send anything, so what [object Object] is the error message talking about?
After using the good old JavaScript debugger I finally figured out that I was supposed to pass null:
app.ports.clickedOutsideDropdown.send(null)
The text was updated successfully, but these errors were encountered:
SSCCE
https://ellie-app.com/6G4Vt26ggBXa1
Result:
Expected something like this:
Story
If I have a port like this…
…and accidentally send a number instead of a string…
…I get this error:
It seems like no matter what type of faulty value I send, it always says
[object Object]
. Which isn’t very helpful :)The browser devtools shows not only the error message, but also which piece of code caused the error. If I click the error location, I’m taken to code looking like this in the devtools debugger:
That comes from here:
core/src/Elm/Kernel/Debug.js
Lines 257 to 260 in fc9d96b
If I put a breakpoint on the
throw
line, it turns out thatproblem
/fact2
isn’t a string, but an object looking like this:That explains where
[object Object]
is coming from. So it looks like it would be possible to say something likeExpecting a STRING, but got: 1337
instead.Background
The other day I was trying to make a port like this:
The JavaScript code only has to tell Elm that a click occurred, but does not need to pass any extra information. That’s why I used unit/
()
in the port.When it was time to implement the JavaScript part, I was thinking: “Since this port does not take any value, do I need to pass anything to
.send
?” So I tried this……which gave me this error:
I was confused. I didn’t send anything, so what
[object Object]
is the error message talking about?After using the good old JavaScript debugger I finally figured out that I was supposed to pass
null
:The text was updated successfully, but these errors were encountered: