Comments (7)
I am getting the same error, it seems to have to do with the parser, at line 43. There's a try..catch structure there, designed to emit an error when the parse failes...
Apparently, sometimes data isnt't formatted properly, which causes the parse to fail. Does anybody know if there's a more solid solution to this? It's something I've come across a lot in Javascript..
Parser.prototype.receive = function receive(buffer) {
this.lastTime = new Date().getTime();
this.buffer += buffer.toString('utf8');
var index, json;
// We have END?
while ((index = this.buffer.indexOf(Parser.END)) > -1) {
json = this.buffer.slice(0, index);
this.buffer = this.buffer.slice(index + Parser.END_LENGTH);
if (json.length > 0) {
try {
json = JSON.parse(json);
this.emit('_data', json);
} catch (error) {
this.emit('error', json);
}
}
}
};
from ntwitter.
Same for me but I get
Error: Uncaught, unspecified 'error' event.
at EventEmitter.emit (events.js:50:15)
at ClientRequest. (/Users/io/Proj/feetshot/node_modules/ntwitter/lib/twitter.js:251:14)
at ClientRequest.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1261:11)
at HTTPParser.onHeadersComplete (http.js:102:31)
at CleartextStream.ondata (http.js:1150:24)
at CleartextStream._push (tls.js:375:27)
at SecurePair.cycle (tls.js:734:20)
at EncryptedStream.write (tls.js:130:13)
at Socket.ondata (stream.js:38:26)
from ntwitter.
+1...have been seeing this as well.
from ntwitter.
@nicolagreco I got the same error message.
I tried
stream.on('error', function(error){
console.log(arguments);
});
and i got { '0': 'http', '1': 406 }
406 is for Not Acceptable.
Wondering why i'm getting this error.
My Setup : Node 0.6.11 , ntwitter 0.2.8 on Windows 7.
from ntwitter.
This is caused whenever you have an uncaught exception in your stream.on('data')
callback. Humorously, that's why it appears so random. lol.
At any rate, here is the associated code:
try {
json = JSON.parse(json);
this.emit('_data', json);
} catch (error) {
this.emit('error', json);
}
The trycatch is no doubt meant to catch only the JSON.parse error, but do to the sychronous nature of EventEmitter.emit, it actually catching any error's in the user's stream.on('data')
callback as well. You could handle this one of two ways,
by not emitting synchronously, which leaves most of the code the same:
try {
json = JSON.parse(json);
process.nextTick(this.emit.bind(this, '_data', json));
} catch (error) {
this.emit('error', json);
}
or by only catching the parse error and additionally, returning the actual error, or a new type of error:
try { json = JSON.parse(json); } catch (error) {
this.emit('error', new Error('Invalid JSON returned - '+error.message);
// You should always throw error objects, not strings,
// but alternatively as it was before...
// this.emit('error', json);
}
this.emit('_data', json);
from ntwitter.
Nice find @CrabBot. I had actually found this a while ago but I did not realize it was related to this issue.
The solution I went with was the first one, process.nextTick()
.
from ntwitter.
I submitted a pull request to resolve this. Since the try/catch is only there to catch the JSON.parse(), I prefer to limit it to the line in general to avoid situations like this. We don't really need process.nextTick()
since we've already asynced since the initial call.
Additionally, since it causes problems for users/libraries/stack traces/situations like this when you don't, I throw a real error.
Cheers!
from ntwitter.
Related Issues (20)
- Does streaming work with 1.1 API? HOT 2
- status/firehose doesn't work HOT 5
- reportSpam doesnt work
- Add additional collaborators? HOT 5
- Update with Media
- Rate Limit Status url is wrong
- showUser doesn't work with numerical usernames
- Is stream.on('end') always called when the connection is closed?
- Issue with the twitter API and ntwitter package
- doing more complex queries
- authorize_url vs. authenticate_url
- Post from multiple accounts
- I get some problems when i use ntwitter HOT 1
- Refresh the track list of a stream HOT 3
- Unspecified 'error' event HOT 2
- Add statuses/lookup entry point
- connect "ECONNREFFUSED" Error.
- Updated Fork (For anyone who needs this library)
- What was this deprecated in favour of?
- Login Twitter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ntwitter.