Skip to content

fix(newsfeed): prevent duplicate parse error callback when using pipeline#4083

Merged
khassel merged 1 commit intoMagicMirrorOrg:developfrom
KristjanESPERANTO:pipe
Apr 3, 2026
Merged

fix(newsfeed): prevent duplicate parse error callback when using pipeline#4083
khassel merged 1 commit intoMagicMirrorOrg:developfrom
KristjanESPERANTO:pipe

Conversation

@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator

In PR #4072 GitHub Bot complained that newsfeedfetcher.js used the old .pipe() method to connect streams (HTTP body → iconv decoding → RSS parser). .pipe() has a weakness: errors in one stream are not automatically forwarded to downstream streams. An I/O or decoding error would silently disappear.

Solution

Replaced .pipe() with await stream.promises.pipeline(). The pipeline() API is designed to propagate errors correctly through the entire chain and to clean up all streams on failure. Errors now reliably land in the catch block and call fetchFailedCallback exactly once. The redundant parser.on("error") handler was removed, as it would have caught the same error again and called the callback a second time.

Why not the bot's suggested fix?

The GitHub Bot suggested the older callback-based stream.pipeline(callback) variant:

stream.pipeline(nodeStream, iconv.decodeStream(...), parser, (error) => {
    if (!error) return;
    // error handling...
});

This has two drawbacks compared to my approach:

  1. It uses the older callback style — stream.promises.pipeline() with async/await is the modern, more readable API.
  2. The bot's suggestion kept both the parser.on("error") handler and the catch block, which would not have fixed the double-callback problem.

Related to #4073

@khassel khassel merged commit 19c6489 into MagicMirrorOrg:develop Apr 3, 2026
9 checks passed
@KristjanESPERANTO KristjanESPERANTO mentioned this pull request Apr 3, 2026
@KristjanESPERANTO KristjanESPERANTO deleted the pipe branch April 3, 2026 17:16
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

Successfully merging this pull request may close these issues.

2 participants