Cannot set property 'text' of undefined"

Ran into an issue where I couldn't set up an email action on a watch in Kibana 6.1.1 and was getting this error in the kibana log:

"error":{"message":"Uncaught error: Cannot set property 'text' of undefined","name":"TypeError","stack":"TypeError: Uncaught error: Cannot set property 'text' of undefined\n at EmailAction.get upstreamJson [as upstreamJson] (D:/Program Files/Kibana/kibana-6.1.1/plugins/x-pack/plugins/watcher/server/models/action/email_action.js:48:7)\n at action (D:/Program Files/Kibana/kibana-6.1.1/plugins/x-pack/plugins/watcher/server/models/watch/threshold_watch/build_actions.js:10:27)\n at arrayEach (D:\Program Files\Kibana\kibana-6.1.1\plugins\x-pack\node_modules\lodash\index.js:1289:13)\n at D:\Program Files\Kibana\kibana-6.1.1\plugins\x-pack\node_modules\lodash\index.js:3345:13\n at buildActions (D:/Program Files/Kibana/kibana-6.1.1/plugins/x-pack/plugins/watcher/server/models/watch/threshold_watch/build_actions.js:9:3)\n at ThresholdWatch.get watchJson [as watchJson] (D:/Program Files/Kibana/kibana-6.1.1/plugins/x-pack/plugins/watcher/server/models/watch/threshold_watch/threshold_watch.js:51:18)\n at handler (D:/Program Files/Kibana/kibana-6.1.1/plugins/x-pack/plugins/watcher/server/routes/api/watch/register_execute_route.js:31:73)\n at Object.internals.handler (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\lib\handler.js:96:36)\n at Items.serial (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\lib\handler.js:63:26)\n at done (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\node_modules\items\lib\index.js:31:25)\n at done (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\node_modules\items\lib\index.js:63:25)\n at pre (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\lib\handler.js:52:24)\n at finalize (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\lib\handler.js:281:20)\n at wrapped (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hoek\lib\index.js:875:20)\n at internals.Response._processPrepare (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\lib\response.js:521:16)\n at internals.Response._prepare (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\lib\response.js:460:21)\n at process.nextTick (D:\Program Files\Kibana\kibana-6.1.1\node_modules\hapi\lib\reply.js:152:22)\n at _combinedTickCallback (internal/process/next_tick.js:73:7)\n at process._tickDomainCallback (internal/process/next_tick.js:128:9)"},"url":{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":"","query":{},"pathname":"/api/watcher/watch/execute","path":"/api/watcher/watch/execute","href":"/api/watcher/watch/execute"},"message":"Uncaught error: Cannot set property 'text' of undefined"}
{"type":"response","@timestamp":"2018-01-16T20:53:43Z","tags":[],"pid":1640,"method":"put","statusCode":500,"req":{"url":"/api/watcher/watch/execute","method":"put","headers":{"host":"host:5601","connection":"keep-alive","content-length":"692","accept":"application/json, text/plain, /","origin":"http://host:5601","kbn-version":"6.1.1","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36","content-type":"application/json;charset=UTF-8","referer":"http://host:5601/app/kibana","accept-encoding":"gzip, deflate","accept-language":"en-US,en;q=0.9"},"remoteAddress":"10.2.100.175","userAgent":"10.2.100.175","referer":"http://host:5601/app/kibana"},"res":{"statusCode":500,"responseTime":40,"contentLength":9},"message":"PUT /api/watcher/watch/execute 500 40ms - 9.0B"}

Looks like this might be fixed by changing line 48 of email_action.js from:
optionalFields.body.text = this.body;
to:
optionalFields.body = this.body;

and line 78 from:
optionalFields.body = json.actionJson.email.body.text;
to:
optionalFields.body = json.actionJson.email.body;

:slight_smile:

Apparently this was fixed in 6.1.2. Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.