[Bug] Newsfeed crashes when an Atom summary is parsed as an object
Environment
MagicMirror version: 2.37.0 Node.js version: 24.11.0 npm version: 11.11.0 Platform: Raspberry Pi 5 Operating system: Raspberry Pi OS Bookworm Process manager: PM2
Which start option are you using?
node --run start:x11
Are you using PM2?
Yes
Module
newsfeed
Have you tried disabling other modules?
- Yes
- No
Have you searched if someone else has already reported the issue on the forum or in the issues?
- Yes
What did you do?
Newsfeed crashes when an Atom summary is parsed as an object
Description
The default newsfeed module fails to process the VRT NWS Atom feed:
https://www.vrt.be/vrtnieuws/nl.rss.articles.xml
MagicMirror logs the following error:
[ERROR] [newsfeed] https://www.vrt.be/vrtnieuws/nl.rss.articles.xml - Stream processing failed: this.buffers[0].slice is not a function
[ERROR] [newsfeed] Error: Could not fetch newsfeed: https://www.vrt.be/vrtnieuws/nl.rss.articles.xml Stream processing failed: this.buffers[0].slice is not a functionEnvironment
- MagicMirror version: 2.37.0
- Node.js version: 24.11.0
- npm version: 11.11.0
- Platform: Raspberry Pi 5
- Operating system: Raspberry Pi OS Bookworm
- Process manager: PM2
Reproduction
Configure the default newsfeed module with:
{
title: "VRT NWS",
url: "https://www.vrt.be/vrtnieuws/nl.rss.articles.xml"
}Restart MagicMirror.
The feed is downloaded successfully, but processing fails with:
this.buffers[0].slice is not a functionThe URL responds successfully after its redirect:
HTTP/2 301
HTTP/2 200
content-type: application/atom+xml;charset=utf-8Investigation
Parsing all 50 feed entries with feedme showed that five entries return summary as an object rather than a string:
ITEM 2 FIELD summary TYPE object VALUE { type: 'text' }
ITEM 4 FIELD summary TYPE object VALUE { type: 'text' }
ITEM 6 FIELD summary TYPE object VALUE { type: 'text' }
ITEM 45 FIELD summary TYPE object VALUE { type: 'text' }
ITEM 47 FIELD summary TYPE object VALUE { type: 'text' }
Finished: 50 items, 5 non-string fieldsThe relevant code in defaultmodules/newsfeed/newsfeedfetcher.js selects the first available description field:
let description = item.description || item.summary || item.content || "";It later passes description to htmlToText() without checking whether it is a string.
When description is { type: "text" }, html-to-text/htmlparser2 ultimately throws:
this.buffers[0].slice is not a functionWorkaround
Adding a type guard before calling htmlToText() prevents the whole feed from failing:
let description = item.description || item.summary || item.content || "";
if (typeof description !== "string") {
Log.warn(`Unexpected non-string description for ${this.url}:`, description);
description = "";
}After this change, the VRT newsfeed loads normally. Entries with object-valued summaries are retained with an empty description instead of crashing the complete feed.
Expected behavior
A malformed or unusually parsed description or summary in one feed item should not prevent the entire feed from loading.
The newsfeed module should either:
- normalize supported object structures into text;
- discard only the invalid description field; or
- skip only the affected item while continuing to process the remaining entries.
What did you expect to happen?
A malformed or unusually parsed description or summary in one feed item should not prevent the entire feed from loading.
The newsfeed module should either:
- normalize supported object structures into text;
- discard only the invalid description field; or
- skip only the affected item while continuing to process the remaining entries.
What actually happened?
The default newsfeed module fails to process the VRT NWS Atom feed:
https://www.vrt.be/vrtnieuws/nl.rss.articles.xml
MagicMirror logs the following error:
[ERROR] [newsfeed] https://www.vrt.be/vrtnieuws/nl.rss.articles.xml - Stream processing failed: this.buffers[0].slice is not a function [ERROR] [newsfeed] Error: Could not fetch newsfeed: https://www.vrt.be/vrtnieuws/nl.rss.articles.xml Stream processing failed: this.buffers[0].slice is not a function
Additional comments
diff --git a/defaultmodules/newsfeed/newsfeedfetcher.js b/defaultmodules/newsfeed/newsfeedfetcher.js index b6b86fe5..5e2ae3a7 100644 --- a/defaultmodules/newsfeed/newsfeedfetcher.js +++ b/defaultmodules/newsfeed/newsfeedfetcher.js @@ -152,6 +152,10 @@ class NewsfeedFetcher { parser.on("item", (item) => { const title = item.title; let description = item.description || item.summary || item.content || "";
if (typeof description !== "string") {Log.warn(`Unexpected non-string description for ${this.url}:`, description);description = "";} const pubdate = item.pubdate || item.published || item.updated || item["dc:date"] || item["a10:updated"]; const url = item.url || item.link || "";
Participation
- I am willing to submit a pull request for this change.
Source: MagicMirrorOrg/MagicMirror