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

How to catch Sax errors? #109

Open
OliverJAsh opened this issue May 5, 2014 · 9 comments
Open

How to catch Sax errors? #109

OliverJAsh opened this issue May 5, 2014 · 9 comments

Comments

@OliverJAsh
Copy link

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)
@danmactough
Copy link
Owner

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

@OliverJAsh
Copy link
Author

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
Copy link
Author

Bump.

@danmactough
Copy link
Owner

@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.

@OliverJAsh
Copy link
Author

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
Copy link
Author

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

@danmactough
Copy link
Owner

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?

@OliverJAsh
Copy link
Author

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.

@danmactough
Copy link
Owner

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

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