Skip to content

Commit 326f92b

Browse files
committed
Website: improve error docs page for contributors
If quick-lint-js' wasm thingy is out of date, visiting the error documentation page of the website can fail with a 500 internal server error. Make the error message prettier and include information on how to likely resolve the error. This commit should hopefully not affect the public website.
1 parent c27d6c1 commit 326f92b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

website/public/errors/index.ejs.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
let moduleCacheBust = "#" + Date.now();
1111

1212
let {
13+
ProblemsError,
1314
documentationDirectoryPath,
1415
loadErrorDocumentationFilesAsync,
1516
reportProblemsInDocumentsAsync,
@@ -20,7 +21,6 @@
2021
let documents = await loadErrorDocumentationFilesAsync(
2122
documentationDirectoryPath
2223
);
23-
await reportProblemsInDocumentsAsync(documents);
2424
//%>
2525
</script>
2626
<title>quick-lint-js: errors and warnings</title>
@@ -75,6 +75,21 @@ <h1><a href="../">quick-lint-js</a></h1>
7575
quick-lint-js can find the following warnings and errors in your code:
7676
</p>
7777

78+
<% try { await reportProblemsInDocumentsAsync(documents); } catch (e) { if
79+
(e instanceof ProblemsError) { %>
80+
<div
81+
style="background-color: #fdd; border: 1px solid #f00; padding: 0.5em"
82+
>
83+
<p>
84+
quick-lint-js found inconsistencies in the error documentation. If
85+
you're hacking on the website, rebuild quick-lint-js for the website
86+
by following <code>wasm/README.md</code> and
87+
<code>website/README.md</code>.
88+
</p>
89+
<p style="white-space: pre-line"><%= e %></p>
90+
</div>
91+
<% } else { throw e; } } %>
92+
7893
<ul class="table-of-contents">
7994
<% for (let doc of documents) { %>
8095
<li>

website/src/error-documentation.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export async function reportProblemsInDocumentsAsync(documents) {
239239
foundProblems.push(...(await doc.findProblemsAsync()));
240240
}
241241
if (foundProblems.length !== 0) {
242-
throw new Error(
242+
throw new ProblemsError(
243243
`found problems in error documents:\n${foundProblems.join("\n")}`
244244
);
245245
}
@@ -266,6 +266,8 @@ export async function loadErrorDocumentationFilesAsync(rootPath) {
266266
return documents;
267267
}
268268

269+
export class ProblemsError extends Error {}
270+
269271
// quick-lint-js finds bugs in JavaScript programs.
270272
// Copyright (C) 2020 Matthew "strager" Glazar
271273
//

0 commit comments

Comments
 (0)