1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
export function prepareRunErrorsEmail(runs) {
if ((runs?.length ?? 0) === 0) {
return "";
}
const byVal = {};
for (let run of runs) {
const valId = run.val.id;
// TODO: handle vals without an id
if (!valId)
continue;
byVal[valId] = byVal[valId] ? [...byVal[valId], run] : [run];
}
function errorMessage(err) {
if (err && "message" in err) {
return err.message;
}
return `${err}`;
}
function errorLine(run) {
return `Error: <a href="https://www.val.town/v/${
run.val.username.replace(/^@/, "")
}.${run.val.name}/evaluations/${run.id}"><code>${
errorMessage(run.error)
}</code></a>`;
}
const html = Object.keys(byVal).map((valId) => {
const valRuns = byVal[valId];
const val = valRuns[0].val;
const errorDescription = `
<ul>
${valRuns.map((run) => `<li>${errorLine(run)}</li>`).join("\n")}
</ul>`;
return `<div>
<h2>${val.username}.${val.name}</h2>
${errorDescription}
</div>`;
}).join("\n");
return html;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023