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

Not catching error on handler? #71

Open
marcelourbanolima opened this issue Jun 22, 2017 · 1 comment
Open

Not catching error on handler? #71

marcelourbanolima opened this issue Jun 22, 2017 · 1 comment

Comments

@marcelourbanolima
Copy link

marcelourbanolima commented Jun 22, 2017

Hi, I'm not expert in javascript/node so I'm probably doing something wrong but, could someone please help and tell me why the error is not being caught in .on('endElement', f1) when f1 contains errors?

'use strict';

const XmlStream = require('xml-stream')
const fs        = require('fs')

let s1 = fs.ReadStream('node_modules/xml-stream/examples/collect-preserve.xml')

let x1 = new XmlStream(s1)

x1.on('error', () => {console.log('Error never caught')})
x1.collect('subitem')
x1.on('endElement: item', f1)


function f1(xmlItem) {
  console.log('enter function')
//  console.log(undefined.split()) // error never caught
  console.log(xmlItem)
  console.log('leave function')
}

/* expected output:
enter function
{ subitem: [ 'one', 'two', 'three' ], '$text': '1 2 3' }
leave function
enter function
{ subitem: [ 'four', { letter: 'B', '$text': 'five' } ],
  '$text': '4 5' }
leave function

received output:
enter function
*/
@andreyrd
Copy link

Seems like on will swallow all errors. I had to wrap my entire on handler in a try/catch just to see errors.

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

2 participants