Skip to content

Commit 296b672

Browse files
committed
Improve the error reporting in checkAudiences().
1 parent 0889270 commit 296b672

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

index.html

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,37 @@
3030
'required-sections': false,
3131
},
3232
preProcess: [
33-
function checkAudiences() {
33+
function checkAudiences(_conf, _doc, utils) {
3434
// Ensure every principle has a data-audiences attribute with a
3535
// space-separated list of the target audiences of that principle.
36-
let errors = Array.from(document.querySelectorAll('div.practice')
37-
).flatMap(practice => {
38-
const audiences = practice.dataset.audiences?.split(/\s+/) ?? [];
39-
if (audiences.length === 0) {
40-
return `Missing data-audiences attribute in principle "${practice.textContent}".`;
41-
}
42-
const unknownAudiences = audiences.filter(
43-
audience => !['websites', 'user-agents', 'api-designers'].includes(audience));
44-
if (unknownAudiences.length > 0) {
45-
return `Unknown audience "${unknownAudiences.join(', ')}" in principle "${practice.textContent}".`;
46-
}
47-
return [];
48-
});
49-
if (errors.length !== 0) {
50-
throw new Error(errors.join('\n'));
36+
for (const practice of document.querySelectorAll("div.practice")) {
37+
const audiences = practice.dataset.audiences?.split(/\s+/) ?? [];
38+
if (audiences.length === 0) {
39+
utils.showError(
40+
`Missing data-audiences attribute in principle.`,
41+
{
42+
title: "Missing data-audiences attribute.",
43+
elements: [practice],
44+
hint: 'Set it to a space-separated list of "websites", "user-agents", or "api-designers".',
45+
}
46+
);
47+
continue;
48+
}
49+
const unknownAudiences = audiences.filter(
50+
(audience) =>
51+
!["websites", "user-agents", "api-designers"].includes(audience)
52+
);
53+
if (unknownAudiences.length > 0) {
54+
const list = new Intl.ListFormat().format(unknownAudiences);
55+
utils.showError(
56+
`Unknown audience "${list}" in principle.`,
57+
{
58+
title: "Unknown audience in data-audience attribute.",
59+
elements: [practice],
60+
hint: `Remove ${list}.`,
61+
}
62+
);
63+
}
5164
}
5265
}
5366
],

0 commit comments

Comments
 (0)