Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop parsing within on('data') or transform() #23

Closed
gudmundur opened this issue Mar 21, 2012 · 4 comments
Closed

Stop parsing within on('data') or transform() #23

gudmundur opened this issue Mar 21, 2012 · 4 comments

Comments

@gudmundur
Copy link

I am attempting to do simple data validation within a .on('data') callback, and when I bump in to an error, I would like to stop the parsing. I've attempted to throw an error, but it seems that it bubbles up out of the csv package, ie. is not caught and passed on to .on('error').

csv().from('...').on('data', function(data, index) { throw new Error('insufficient data in message'); }).on('error', function(err) { console.log('I never get called :('); });

The stacktrace I am getting is

Error: insufficient data in message
    at [object Object].<anonymous> (/Users/gudmundur/Development/CSharp/Sources/vmkerfi/tools.ssBridge/lib/bridge.coffee:114:35)
    at [object Object].emit (events.js:70:17)
    at write (/Users/gudmundur/Development/CSharp/Sources/vmkerfi/tools.ssBridge/node_modules/csv/lib/csv.js:222:17)
    at flush (/Users/gudmundur/Development/CSharp/Sources/vmkerfi/tools.ssBridge/node_modules/csv/lib/csv.js:409:9)
    at [object Object].end (/Users/gudmundur/Development/CSharp/Sources/vmkerfi/tools.ssBridge/node_modules/csv/lib/csv.js:143:17)
    at Array.0 (/Users/gudmundur/Development/CSharp/Sources/vmkerfi/tools.ssBridge/node_modules/csv/lib/csv.js:83:18)
    at EventEmitter._tickCallback (node.js:192:40)

Am I going about this the wrong way or is this an actual issue?

@wdavidw
Copy link
Member

wdavidw commented Jun 20, 2012

Thank you for reporting this issue, error are now handled in the latest version

@wdavidw wdavidw closed this as completed Jun 20, 2012
@gudmundur
Copy link
Author

Cheers!

@alessioalex
Copy link

I can stop parsing even if an error is thrown and caught with on('error'). The data event is emitted again and again for each line. How can I stop the parsing.. ?

@wdavidw
Copy link
Member

wdavidw commented Jul 26, 2012

Could you please send me a sample, I created a test which read a file, and the error isn't thrown again. A sample would help me to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants