node-feedparser icon indicating copy to clipboard operation
node-feedparser copied to clipboard

How to catch Sax errors?

Open OliverJAsh opened this issue 10 years ago • 9 comments

Sometimes I get sax errors. How can I catch them?

I have kept resume_saxerror to its default value of true.

Error: Unexpected end
Line: 543
Column: 146
Char:
                at error (/Users/Oliver/Development/sbscribe/sbscribe-common/node_modules/feedparser/node_modules/sax/lib/sax.js:642:8)
                at end (/Users/Oliver/Development/sbscribe/sbscribe-common/node_modules/feedparser/node_modules/sax/lib/sax.js:650:64)
                at SAXParser.end (/Users/Oliver/Development/sbscribe/sbscribe-common/node_modules/feedparser/node_modules/sax/lib/sax.js:149:24)
                at SAXStream.end (/Users/Oliver/Development/sbscribe/sbscribe-common/node_modules/feedparser/node_modules/sax/lib/sax.js:234:16)
                at FeedParser._flush (/Users/Oliver/Development/sbscribe/sbscribe-common/node_modules/feedparser/main.js:1012:17)
                at FeedParser.<anonymous> (_stream_transform.js:130:12)
                at g (events.js:180:16)
                at EventEmitter.emit (events.js:92:17)

OliverJAsh avatar May 05 '14 21:05 OliverJAsh

When resume_saxerror is true, they are emitted on error. Are you not getting them in your error handler?

danmactough avatar May 05 '14 21:05 danmactough

Regardless of whether I have resume_saxerror set to true or false, I am getting an uncaught exception – despite the fact I have an error event listener.

var feedParser = new FeedParser({
    addmeta: false,
    feedurl: feedUrl,
    resume_saxerror: true
});

feedParser.on('error', function () {
    // This is called, but it does not *catch* the error.
    console.log('feedParser error', arguments);
});

OliverJAsh avatar May 05 '14 22:05 OliverJAsh

Bump.

OliverJAsh avatar May 30 '14 18:05 OliverJAsh

@OliverJAsh I'm working on refactoring SAX error handling, which I believe is actually a bit broken in sax. Still digging.

Your code about doesn't have a parameter for the error handler. Are you sure it's being triggered by the error that gets thrown? Or that the "Unexpected end" error after you've already handled the other error, possibly.

danmactough avatar May 30 '14 21:05 danmactough

It is being triggered by the error that gets thrown because I am seeing the error logged to the console (I just log the arguments which contains the error).

OliverJAsh avatar May 31 '14 12:05 OliverJAsh

However, it is immediately followed by the uncaught exception, from the same error.

OliverJAsh avatar May 31 '14 12:05 OliverJAsh

That sounds like the error is not getting cleared for some reason. If sax resumes parsing and the error has not been cleared, it will throw -- intentionally throw.

I cannot reproduce this behavior, though. Can you post a gist or something with runnable code that does this so I can help you debug it?

danmactough avatar May 31 '14 12:05 danmactough

I have this problem when parsing http://theramblingtour.smugglersrecords.com/?feed=rss2 with the following code:

feedParser
    .on('error', function (error) {
        // This should catch the error, but it doesn't.
    })
    .on('readable', function () {
        this.end();
    });

The error only occurs upon this feed when I call this.end() in the readable event. If I don't call that error, it doesn't error – I imagine because we aren't pulling any data through the stream?

If you still can't reproduce it with that information, I’ll have a go at creating an isolated case in a gist for you.

OliverJAsh avatar May 31 '14 14:05 OliverJAsh

I did this: https://gist.github.com/danmactough/342c037d8094ce1a553d and cannot reproduce.

danmactough avatar May 31 '14 17:05 danmactough