Pin pointing error in fucntion script

I'm getting an error on a function script but I'm not really sure where in the code. Below is the error, does it tell me a line number or anything as there's lot of numbers here so not sure which it is

TypeError: Cannot read properties of undefined (reading 'substring')
    at Function node:8b6c7c7b38a2dcf0 [Build CXML]:8:27
    at Function node:8b6c7c7b38a2dcf0 [Build CXML]:215:3
    at Script.runInContext (node:vm:149:12)
    at processMessage (/usr/src/node-red/node_modules/@node-red/nodes/core/function/10-function.js:430:37)
    at FunctionNode._inputCallback (/usr/src/node-red/node_modules/@node-red/nodes/core/function/10-function.js:348:17)
    at /usr/src/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:214:26
    at Object.trigger (/usr/src/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
    at Node._emitInput (/usr/src/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:206:11)
    at Node.emit (/usr/src/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:190:25)

That means you have tried to call substring() but the thing you are calling it on is undefined. So for example you might have msg.payload.substring(..) but msg.payload does not exist. Look for all uses of substring in the function and hopefully it will give you a clue.

Hi Colin, I get that but does the error give me a clue which line it's on as there are a few substring in the code

What does the function have around line 8 (perhaps line 7)?

1 Like