koles/ya-csv

Don't crash when passed a binary file

Closed this issue · 5 comments

Now it crashes all nodejs app:

node_modules/ya-csv/lib/ya-csv.js:131
 throw new Error("separator expected after a closin
Error: separator expected after a closing quote; found 

It should handle the error gracefully.

why can't you just wrap a try/catch around the code?

Because that's not how nodejs works. In the core node.js libraries, the only place that one really needs to use a try-catch is around JSON.parse(). All of the other methods use either the standard Error object through the first parameter of the callback or emit an error event. Because of this, it is generally considered standard to return errors through the callback rather than to use the throw statement.

More info:
http://stackoverflow.com/questions/5999373/how-do-i-prevent-node-js-from-crashing-try-catch-doesnt-work
http://docs.nodejitsu.com/articles/errors/what-is-try-catch

User code should be

reader.addListener('data', function(err, data) {
...

just like the other libraries.

Got this problem too! Scary issue since it will knock over the whole Node sever. Please fix!

Same here, any idea how to handle this ?

koles commented

This has been fixed a long time ago. Ya-csv emits an 'error' event in the case of an error. Sorry for not closing the ticket formally. Error handling has been added to the examples in the README file.