Troubleshooting
Relevant source files
The following files were used as context for generating this wiki page: - [README.md](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/README.md) - [package.json](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/package.json) - [scripts/validate.js](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/scripts/validate.js) - [server.js](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/server.js) - [utils/index.js](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/utils/index.js) - [utils/__tests__/utils.test.js](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/utils/__tests__/utils.test.js) - [scripts/collect-retrospective.js](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/scripts/collect-retrospective.js) - [scripts/build-rss.js](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/scripts/build-rss.js) - [scripts/format.js](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/scripts/format.js) - [add-post.html](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/add-post.html) - [config.json](https://github.com/thomas-iniguez-visioli/nodejs-news-feeder/blob/HEAD/config.json)This document provides guidance for diagnosing and resolving common issues within the Node.js News Feeder project. It covers problems related to data collection, feed generation (RSS and HTML), and the local development environment. The primary areas for investigation include the data collection scripts, content processing utilities, feed validation, and the manual post-addition server.
The system relies on a series of Node.js scripts orchestrated via npm commands to fetch, process, and build the final feed.xml and index.html files. Understanding the flow of data from various sources (GitHub, external RSS feeds) through these scripts is key to effective troubleshooting.
Initial Checks & Diagnostics
Before diving into specific components, running the built-in quality checks can often identify the root cause of an issue quickly.
Running Linter and Tests
Code consistency and logical errors can be caught by the linter and test suite. Use the following npm scripts to check the codebase.
| Command | Description |
|---|---|
npm run lint | Runs the standard linter to check for style issues. |
npm run lint:fix | Automatically fixes style issues found by the linter. |
npm run test | Executes the test suite using Node.js's built-in test runner. |
npm run test:watch | Runs the tests in watch mode, re-running them on file changes. |
npm run test:coverage | Runs tests and generates a code coverage report. |
The tests, particularly in utils/__tests__/utils.test.js, validate the behavior of critical data cleaning and formatting functions. If tests fail, it often points to a regression or an issue in the utility functions that affects the entire data processing pipeline.
Sources: package.json:11-16, utils/tests/utils.test.js
Validating the RSS Feed
If the feed.xml is malformed, it will not be consumable by RSS readers. The project includes a script to validate the feed against the W3C Feed Validation Service.
To run the validation:
npm run rss:validate
This command executes the scripts/validate.js script. It reads the local feed.xml, sends it to the W3C validator, and prints the results. If the output contains "Sorry", the feed is invalid.
The following diagram illustrates the feed validation process.
Sources: scripts/validate.js, package.json:8, README.md:65-67
Data Collection Issues
Problems can arise when fetching data from external sources like the GitHub API or other RSS feeds. These issues are typically related to network connectivity, API authentication, or changes in the source data format.
The overall data collection process is managed by a series of collect-*.js scripts.
This diagram shows the high-level data flow for content aggregation.
GitHub API Failures
The scripts collect-issues.js, collect-discussions.js, and collect-releases.js use gh-got and @octokit/graphql to fetch data from GitHub. Common failure points include:
- Missing
GITHUB_TOKEN: These scripts require aGITHUB_TOKENenvironment variable for authentication. If it's missing or invalid, API requests will fail. - Pagination Limits: The
config.jsonfile defines pagination limits (reposPaginationLimit,releasePaginationLimit,commentsPaginationLimit). If these are too low, the scripts may not fetch all relevant data. - Scope Changes: The
issuesInScopeanddiscussionsInScopearrays inconfig.jsondefine which repositories and discussions to query. Incorrect values here will lead to missing data.
Sources: scripts/collect-issues.js:7-14, scripts/collect-discussions.js:6-24, config.json:2-10
External Feed and Scraper Failures
The scripts/collect-retrospective.js script is responsible for fetching data from multiple external sources, including RSS feeds and by scraping HTML from bonjourlafuite.eu.org.
- Network or DNS Issues: The script uses a custom HTTPS agent with a hardcoded DNS entry (
82.67.8.211) forbonjourlafuite.eu.org. If this IP changes or the site is down, the scraper will fail. - HTML Structure Changes: The scraper relies on specific CSS selectors (
div.timeline-entry,span.timestamp time,h2) to parse data. Any change to the HTML structure of the target site will break the scraper. - RSS Feed Errors: The script fetches multiple RSS feeds (e.g.,
haveibeenpwned.com/feed/breaches/). If any of these feeds are unavailable or malformed,rss-parsermay throw an error. The script includes error handling to log such failures.
Sources: scripts/collect-retrospective.js:6-18, 50-84, 115-136
Feed Generation and Formatting Problems
Issues in this stage usually manifest as malformed XML, incorrect content, or duplicate entries in the final feed.xml and index.html files.
Content Cleaning and Sanitization
All fetched content is processed by utility functions in utils/index.js before being inserted into the feed.
cleancontent(): This is a primary function that removes blacklisted keywords defined inblacklist.txt. An overly aggressive keyword in the blacklist could strip legitimate content.escapeXmlCharacters(): Escapes&,<,>,", and'. Failure here can lead to invalid XML.stripHtmlTags(): Removes HTML tags. If this fails, unintended HTML can appear in the feed's text fields.
The tests in utils/__tests__/utils.test.js provide clear examples of how these functions are expected to behave and can be used to debug them.
Sources: utils/index.js:28-100, utils/tests/utils.test.js:14-177
Duplicate or Outdated Content
The system has several mechanisms to prevent duplicate or outdated content, and failures in these can cause issues.
- Timestamp Check: Most collection scripts use
lastCheckTimestampfromconfig.jsonto fetch only items newer than the last run. If this timestamp is not updated correctly byscripts/build-rss.js, old items may be re-fetched. - GUID Check:
scripts/collect-retrospective.jschecks if aguidalready exists infeed.xmlbefore adding a new item. - Formatting and Sorting: The
scripts/format.jsscript is responsible for the final sorting and filtering of feed items. It uses thefilterFeedItemsutility, which de-duplicates items based onguid,link, ortitle. It then sorts all items by date before overwriting the feed. An error in this script could lead to an incorrectly ordered or unfiltered feed.
Sources: scripts/collect-issues.js:18, scripts/collect-retrospective.js:37-43, scripts/format.js:28-48, scripts/build-rss.js:12-20, config.json:2
Manual Post Addition Server
A local Express server is provided to manually add posts to the feed via a web interface.
Server and API Endpoints
The server is started with npm run start, which runs server.js. It serves add-post.html and provides two API endpoints.
| Method | Endpoint | Description |
|---|---|---|
GET | /api/posts | Reads and returns all posts from manual-posts.json. |
POST | /api/posts | Adds a new post to manual-posts.json. |
The following sequence diagram shows the flow of adding a new post.
Common issues with this feature include:
- File System Errors: The server needs read/write permissions for
manual-posts.json. AnEACCESerror would indicate a permissions issue. - JSON Errors: If
manual-posts.jsonbecomes corrupted or is not valid JSON, the server will fail onJSON.parse()and return a 500 error. - Date Formatting: The server expects a
datetime-localinput but converts it to an ISO string. Incorrect date formats from the client could cause issues.
Sources: server.js, add-post.html