No handler for device.send() being thrown

I just re-ran old code, old device. etc. it’s been a while.

I got an error that does not make sense.

2015-07-07 19:54:17 UTC-5 [Device] ERROR: no handler for device.send()

I have no “device.send” in my Device code because of course this call is not available in the device. I do have agent.send

Unfortunately the error code does not say what handler is missing nor does it indicate a line number so I don’t even know where to start.

ideas?

ugh. just tried to load some old builds and this error still comes up. Seems like a regression. ?

Yes, it would be helpful if the error message for this AND the error messsage for “no handler for agent.send()” mentioned the string key.

it would be helpful if the error message for this AND the error messsage for "no handler for agent.send()" mentioned the string key.

Yeah, that’s a feature we’d like to add.

“no handler for device.send()” means you have a device.send() in your agent code - the error comes from the device because it’s receiving a message and doesn’t have an agent.on(callback) handler registered for that message. Check your agent code for device.send() calls that don’t have a corresponding agent.on handler in the device code. (This is a bit confusing, I agree.)

If you’re not missing any agent.on handlers, the problem could be a race condition: if you’re doing a device.send() as soon as the agent boots, but the agent.on handler on the device is near the bottom of your code, when you hit Build and Run the device may receive the message before it has had a chance to register the handler. In that case, you’d need to either register the handler earlier in the device code or delay the device.send on the agent side, most likely by doing something like this:
imp.wakeup(1, function() { device.send("messageName", data); });

gino, thanks for your prompt response. I am reasonably sure it was a race condition and I corrected it with the exact code you listed.

The error message makes more sense now that my head is clear. I had considered some kind of problem with timing but I was looking in the wrong place at first. This imp controlling my reflow oven and I had just done the paste and placing of parts when I found the error. didn’t help that I was in a time crunch :open_mouth: