Dustin Coates in Alexa

No handler function was defined for event error in Alexa Skills Kit Node.js SDK

I tweeted recently that, of all the big changes that were announced this week, I thought that this was the biggest.

If you’re a beginner and coming to this post from somewhere else, know this: for every state, you need an intent handler for every intent. If you don’t have an intent handler for a given state (and this includes the “no state” state), you need a handler called Unhandled. This should be on each state where an intent might be triggered and not defined.

Previously, the error message was `No 'Unhandled' function defined for event: ${eventString}`. Take a cursory look online and you’ll see that this was one of the most common stumbling points for beginners using the Alexa Skills Kit SDK for Node.js. The ‘Unhandled’ function? What in the world does that mean?

Now, the error message is:

`In state: ${this.state}. No handler function was defined for event ${handlerFuncName} ` +
 +            `and no 'Unhandled' function was defined.`

There’s a few things I really like about this:

  • It specifies which state we’re in.
  • It provides the handler name, not the event string (which at this point has been prepended with the state). This is useful, because most people using the SDK would not be building their handler names by prepending the state directly. They would, instead, be using CreateStateHandler.
  • It makes it clear that it needs a handler function (though I think it still may not be entirely clear that Unhandled is indeed a handler itself.)

People will always run into issues when starting something for the first time, but hopefully this cuts down on this error and helps people build skills more quickly.