How to find out wich helper? "Exception in template helper: TypeError: Cannot read property 'toString' of undefined"

Exception in template helper: TypeError: Cannot read property ‘toString’ of undefined
at https://www.smartmeter.se/packages/aldeed_autoform.js?hash=21e9094b6d9891ff4ea0857e72730fe370c878c9:5404:26
at Array.forEach ()
at Function..each..forEach (https://www.smartmeter.se/packages/underscore.js?hash=a29c47e75bce51635cf7f8fcc19c4884c10291d3:149:11)
at Object.contextAdjust (https://www.smartmeter.se/packages/aldeed_autoform.js?hash=21e9094b6d9891ff4ea0857e72730fe370c878c9:5365:7)
at Object.afFieldInputContext (https://www.smartmeter.se/packages/aldeed_autoform.js?hash=21e9094b6d9891ff4ea0857e72730fe370c878c9:7131:78)
at https://www.smartmeter.se/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3051:16
at https://www.smartmeter.se/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:1715:16
at https://www.smartmeter.se/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3103:66
at Function.Template._withTemplateInstanceFunc (https://www.smartmeter.se/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3769:14)
at https://www.smartmeter.se/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3102:27

How do you go hunting for these kind of errors?

The error is thrown in the topmost entry of the call stack. In this instance it appears to be aldeed:autoform. I suggest following steps:

  1. download the module as indicated in the stack trace, e.g.
    wget -O autoform.js https://www.smartmeter.se/packages/aldeed_autoform.js?hash=21e9094b6d9891ff4ea0857e72730fe370c878c9:5404:26
  2. load the downloaded file autoform.js in your editor
  3. go to the line 5404, column 26

_id: opt.value.toString(), with column 26 being .toString. This is where the error is thrown. This code appears to be buried in AutoForm.addInputType() of the module aldeed:autoform – does that ring a bell?

Digging around a bit in that function reveals that there must be a context with selectOptions, where each item is supposed to have a label and a value. It looks like one of the values passed is undefined, that causes this error.

2 Likes