Hello,
I have a function node which throws an error from time to time.
But I can't pin it down where it comes from. This is the stack trace:
22 May 07:53:25 - [error] TypeError: Cannot read property '0' of undefined
at Function node:b8b41c15d84ab98c [Splunk get DemandType]:66:48
..........
What I have read in the node.js stack trace documentation is, that the error occurs on line 66 and column 48.
But the code in the function node doesn't have a column 48 at line 66.
So how can I identify the position of this error?
Thanks!
Here is the function node code:
if(msg.getDemandType == false) {
return msg;
}
//node.warn(msg);
var splunkjs = global.get("splunkjs");
var service = new splunkjs.Service({username: "username",
password: "password",
scheme:"https",
host:"asdf",
port:"123"});
// Search everything and return the first 10 results
var searchQuery = '| inputlookup sensor_data.csv"';
// Set the search parameters--specify a time range
var searchParams = {
id: "myjob_"+msg.sourceName,
earliest_time: "@d",
latest_time: "now"
};
var msgSplunk=false;
service.search(
searchQuery,
searchParams,
function(err, job) {
// Display the job's search ID
//node.warn("Job SID: ", job.sid);
if (err) {
node.warn("Error!");
node.warn(err);
return;
}
// Poll the status of the search job
job.track({period: 200}, {
done: function(job) {
//node.warn("Done!");
try {
// Get the results and print them
job.results({}, function(err, results, job) {
//var fields = results.fields;
var rows = results.rows;
//node.warn(rows[0][0]);
msg.Available = rows[0][0] == "Available" ? true : false;
msgSplunk = true;
node.send(msg);
});
} catch (err) {
node.warn(err);
}
},
failed: function(job) {
node.warn("Job failed")
},
error: function(err) {
node.warn(err);
}
});
}
);