parseUrl callback called twice in error case
Closed this issue · 2 comments
humphd commented
I ran into an issue where the callback to parseUrl
was double-firing, the first time with an error, the second time without. Here's a test case that shows the problem:
const assert = require('assert');
const { parseUrl } = require ("davefeedread");
const url = 'http://cdot-callaghan.posterous.com/rss.xml?tag=CDOT'
let callbackFired = 0;
function callback(err, feed) {
console.log('callback called', err && err.message, feed);
assert.strictEqual(callbackFired, 0);
callbackFired++;
}
parseUrl(url, 30, callback);
And here's the output I get:
callback called Not a feed { head: {}, items: [] }
callback called undefined { head: {}, items: [] }
assert.js:42
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: 1 === 0
at callback (/Users/humphd/repos/planet-clean/test.js:9:12)
at /Users/humphd/repos/planet-clean/node_modules/davefeedread/feedread.js:145:7
at FeedParser.<anonymous> (/Users/humphd/repos/planet-clean/node_modules/davefeedread/feedread.js:104:3)
at emitNone (events.js:111:20)
at FeedParser.emit (events.js:208:7)
at endReadableNT (/Users/humphd/repos/planet-clean/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)
I wonder if the problem is in https://github.com/scripting/feedRead/blob/master/feedread.js#L99-L105. When the error
event happens, it triggers callback
, but then it looks like end
might happen subsequent to this, and cause it to get fired again.
scripting commented
Thanks for the report.
I just added some code to make sure that the callback is called no more than once.
The new version, v0.5.2 is released.
Please let me know if it fixes the problem.
Dave
humphd commented
Yes, verified: v.0.5.2
fixes it. Thanks for doing the update so quickly!