Skip to content

Not catching error on handler? #71

@marcelourbanolima

Description

@marcelourbanolima

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
*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions