Skip to content

Commit

Permalink
Detect draft CSS specs server hiccups
Browse files Browse the repository at this point in the history
The server used to serve draft CSS specs sometimes returns the contents of the
directory instead of the actual spec. The code happily considered that the
content received in such cases was an actual spec and updated the spec title
accordingly, e.g. to "Index of css-animations-2".

This update makes the code throw an error when this happens. This will make the
job fail with an error even though there is nothing that we can really do about
it, but that seems preferable to silently committing invalid titles to
`index.json`.
  • Loading branch information
tidoust authored and dontcallmedom committed Dec 26, 2021
1 parent 5f9793f commit c2397bd
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/fetch-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,32 @@ async function fetchInfoFromSpecs(specs, options) {
};
}
}
// Extract first heading
const h1 = dom.window.document.querySelector("h1");
if (h1) {
return {
nightly: { url: url },
title: h1.textContent.replace(/\n/g, '').trim()
};

// Extract first heading when set
let title = dom.window.document.querySelector("h1");
if (!title) {
// Use the document's title if first heading could not be found
// (that typically happens in Respec specs)
title = dom.window.document.querySelector("title");
}

// Use the document's title if first heading could not be found
// (that typically happens in Respec specs)
const title = dom.window.document.querySelector("title");
if (title) {
title = title.textContent.replace(/\n/g, '').trim();

// The draft CSS specs server sometimes goes berserk and returns
// the contents of the directory instead of the actual spec. Let's
// throw an error when that happens so as not to create fake titles.
if (title.startsWith('Index of ')) {
throw new Error(`CSS server issue detected in ${url} for ${spec.shortname}`);
}

return {
nightly: { url: url },
title: title.textContent.replace(/\n/g, '').trim()
nightly: { url },
title
};
}

throw `Could not find title in ${url} for spec "${spec.shortname}"`;
throw new Error(`Could not find title in ${url} for ${spec.shortname}`);
}));

const results = {};
Expand Down

0 comments on commit c2397bd

Please sign in to comment.