Improve error reporting when firmware downloads fail (#1522)

This commit is contained in:
Tim Wilkinson 2024-09-17 09:32:30 -07:00 committed by GitHub
parent 08f9fe09bc
commit 02881f5baa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 37 additions and 5 deletions

View File

@ -36,7 +36,7 @@
function curl(url, filename, start, len) function curl(url, filename, start, len)
{ {
const name = filename ? filename : `/tmp/download.${time()}`; const name = filename ? filename : `/tmp/download.${time()}`;
const f = fs.popen(`/usr/bin/curl --progress-bar -o ${name} ${url} 2>&1`); const f = fs.popen(`/usr/bin/curl --progress-bar --remove-on-error -o ${name} ${url} 2>&1`);
if (!f) { if (!f) {
return null; return null;
} }
@ -236,8 +236,17 @@
const data = firmware_versions[ver]; const data = firmware_versions[ver];
f = curl(`${aredn_firmware}/afs/www/${data}/overview.json`, null, 10 + count * 90 / firmware_version_count, 90 / firmware_version_count); f = curl(`${aredn_firmware}/afs/www/${data}/overview.json`, null, 10 + count * 90 / firmware_version_count, 90 / firmware_version_count);
if (f) { if (f) {
const info = json(f.read("all")); let info;
try {
info = json(f.read("all"));
}
catch (_) {
}
f.close(); f.close();
if (!info) {
uhttpd.send(`event: error\r\ndata: firmware version downloaded is corrupt\r\n\r\n`);
return;
}
for (let i = 0; i < length(info.profiles); i++) { for (let i = 0; i < length(info.profiles); i++) {
const profile = info.profiles[i]; const profile = info.profiles[i];
if (profile.id === board_type || ((board_type === "qemu" || board_type === "vmware") && profile.id == "generic" && profile.target === "x86/64")) { if (profile.id === board_type || ((board_type === "qemu" || board_type === "vmware") && profile.id == "generic" && profile.target === "x86/64")) {
@ -300,8 +309,17 @@
uhttpd.send(`event: error\r\ndata: missing firmware list\r\n\r\n`); uhttpd.send(`event: error\r\ndata: missing firmware list\r\n\r\n`);
return; return;
} }
const list = json(f.read("all")); let list;
try {
list = json(f.read("all"));
}
catch (_) {
}
f.close(); f.close();
if (!list) {
uhttpd.send(`event: error\r\ndata: firmware list is corrupt\r\n\r\n`);
return;
}
const inst = list[version]; const inst = list[version];
if (!inst) { if (!inst) {
uhttpd.send(`event: error\r\ndata: bad firmware version\r\n\r\n`); uhttpd.send(`event: error\r\ndata: bad firmware version\r\n\r\n`);
@ -312,8 +330,17 @@
uhttpd.send(`event: error\r\ndata: could not download firmware version catalog\r\n\r\n`); uhttpd.send(`event: error\r\ndata: could not download firmware version catalog\r\n\r\n`);
return; return;
} }
const overview = json(f.read("all")); let overview;
try {
overview = json(f.read("all"));
}
catch (_) {
}
f.close(); f.close();
if (!overview) {
uhttpd.send(`event: error\r\ndata: downloaded firmware version catalog is corrupt\r\n\r\n`);
return;
}
let fwimage = null; let fwimage = null;
let booter_version = null; let booter_version = null;
@ -389,7 +416,12 @@
{% {%
const f = fs.open("/tmp/firmware.list"); const f = fs.open("/tmp/firmware.list");
if (f) { if (f) {
const list = json(f.read("all")); let list = {};
try {
list = json(f.read("all"));
}
catch (_) {
}
f.close(); f.close();
for (let k in list) { for (let k in list) {
print(`<option value="${k}">${k}${index(k, "-") == -1 ? "" : " (nightly)"}</option>`); print(`<option value="${k}">${k}${index(k, "-") == -1 ? "" : " (nightly)"}</option>`);