Skip to content

Commit abca7df

Browse files
authored
Add catch for invalid spec URLs (#1620)
1 parent b8501c5 commit abca7df

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

scripts/specs.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ function suggestSpecs(bad: URL): void {
7777
}
7878
}
7979

80-
let checked = 0;
80+
let checkedFeatures = 0;
81+
let checkedSpecs = 0;
8182
let errors = 0;
8283

8384
// Ensure every exception in defaultAllowlist is needed
@@ -92,19 +93,26 @@ for (const [allowedUrl, message] of defaultAllowlist) {
9293
for (const [id, data] of Object.entries(features)) {
9394
const specs = Array.isArray(data.spec) ? data.spec : [data.spec];
9495
for (const spec of specs) {
95-
const url = new URL(spec);
96-
if (!isOK(url)) {
96+
let url: URL;
97+
try {
98+
url = new URL(spec);
99+
} catch (error) {
100+
console.error(`Invalid URL "${spec}" found in spec for "${data.name}"`);
101+
errors++;
102+
}
103+
if (url && !isOK(url)) {
97104
console.error(`URL for ${id} not in web-specs: ${url.toString()}`);
98105
suggestSpecs(url);
99106
errors++;
100107
}
101-
checked++;
108+
checkedSpecs++;
102109
}
110+
checkedFeatures++;
103111
}
104112

105113
if (errors) {
106-
console.log(`\n${checked} features checked, found ${errors} error(s)`);
114+
console.log(`\nChecked ${checkedSpecs} specs in ${checkedFeatures} features, found ${errors} error(s)`);
107115
process.exit(1);
108116
} else {
109-
console.log(`${checked} features checked, no errors`);
117+
console.log(`\nChecked ${checkedSpecs} specs in ${checkedFeatures} features, no errors`);
110118
}

0 commit comments

Comments
 (0)