Skip to content

Commit

Permalink
Improve error messages for the extract pages module
Browse files Browse the repository at this point in the history
Build sometimes fails with a 500 internal server error in the extract pages
module. That error was correctly reported but did not include the URL of the
spec that triggered the error, making it hard to know which spec is causing
troubles.
  • Loading branch information
tidoust authored and dontcallmedom committed Jan 5, 2022
1 parent c91eb34 commit f6e5dbe
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/extract-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
const { JSDOM } = require("jsdom");

module.exports = async function (url) {
const dom = await JSDOM.fromURL(url);
const window = dom.window;
const document = window.document;
try {
const dom = await JSDOM.fromURL(url);
const window = dom.window;
const document = window.document;

const allPages = [...document.querySelectorAll('.toc a[href]')]
.map(link => link.href)
.map(url => url.split('#')[0])
.filter(url => url !== window.location.href);
const pageSet = new Set(allPages);
return [...pageSet];
const allPages = [...document.querySelectorAll('.toc a[href]')]
.map(link => link.href)
.map(url => url.split('#')[0])
.filter(url => url !== window.location.href);
const pageSet = new Set(allPages);
return [...pageSet];
}
catch (err) {
throw new Error(`Could not extract pages from ${url} with JSDOM: ${err.message}`);
}
};

0 comments on commit f6e5dbe

Please sign in to comment.