Reputation: 7747
I have an error, but I'm not sure what it means or how to debug it. Here's the error:
events.js:74
throw TypeError('Uncaught, unspecified "error" event.');
^
TypeError: Uncaught, unspecified "error" event.
at TypeError (<anonymous>)
at EventEmitter.emit (events.js:74:15)
at EventEmitter.receive (/home/andy/dev/node/tweetmap/node_modules/ntwitter/lib/parser.js:41:14)
at IncomingMessage.<anonymous> (/home/andy/dev/node/tweetmap/node_modules/ntwitter/lib/twitter.js:266:14)
at IncomingMessage.EventEmitter.emit (events.js:95:17)
at IncomingMessage.<anonymous> (_stream_readable.js:736:14)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
My code is as follows:
twit.stream('statuses/filter', { locations: locs, track: tracks }, function(stream) {
stream.on('data', function (data) {
var geo=false,latitude,longitude;
if(data.geo!=null){
geo = true;
latitude = data.geo.coordinates[0];
longitude = data.geo.coordinates[1];
var sentiment;
sentiment(data.text, function (err, result) {
sentiment = result.score;
io.sockets.volatile.emit('tweets', {
user: data.user.screen_name,
text: data.text,
geo : geo,
latitude: latitude,
longitude: longitude,
sentiment: sentiment
});
});
}
});
});
My code worked fine until I added the sentiment function, so I think this has something to do with the async nature of the call. Can anyone help me here?
Upvotes: 0
Views: 4668
Reputation: 10399
You're attempting to call undefined
.
var sentiment;
console.log(typeof sentiment === 'undefined') // true
sentiment(data.text, function (err, result) {
Try something like this:
var _sentiment;
sentiment(data.text, function (err, result) {
_sentiment = result.score;
io.sockets.volatile.emit('tweets', {
user: data.user.screen_name,
text: data.text,
geo : geo,
latitude: latitude,
longitude: longitude,
sentiment: _sentiment
});
});
}
Upvotes: 2