Page type-check: strict's flags that cost nothing, and catch variables as unknown (#235)

why(e) gives a caught error's message; each catch read e.message as any.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 15:51:41 +00:00
parent f20660a7d5
commit 78704e40f2
7 changed files with 36 additions and 28 deletions

View File

@@ -66,7 +66,7 @@ async function drawServer(){
max_age_days: Number($('#gage').value) || 0,
art_cache_mb: Math.max(0, Number($('#gart').value) || 0)})});
toast('Settings saved');
}catch(e){ toast(e.message, true); }
}catch(e){ toast(why(e), true); }
};
}
@@ -99,7 +99,7 @@ async function drawDirectorySettings(){
await api('/api/settings', {method: 'PATCH', body: JSON.stringify(patch)});
toast(said);
drawDirectorySettings();
}catch(e){ toast(e.message, true); }
}catch(e){ toast(why(e), true); }
};
$('#dsave').onclick = () => {
const patch: Record<string, unknown> = {directory_url: $('#durl').value.trim(), directory_share: $('#dshare').checked};
@@ -115,7 +115,7 @@ async function drawDirectorySettings(){
async function drawDirectoryStatus(){
const el = $('#dstatus');
let s;
try{ s = await api('/api/directory-status'); }catch(e){ el.textContent = e.message; return; }
try{ s = await api('/api/directory-status'); }catch(e){ el.textContent = why(e); return; }
if(!el.isConnected) return;
const lines: string[] = [];
if(!s.configured) lines.push('Not set up: it needs an address and a token.');
@@ -138,7 +138,7 @@ async function drawDirectoryStatus(){
async function drawDirectoryAdmin(){
const box = $('#dadmin');
let a;
try{ a = await api('/api/directory-admin'); }catch(e){ box.innerHTML = `<p class="hint">${esc(e.message)}</p>`; return; }
try{ a = await api('/api/directory-admin'); }catch(e){ box.innerHTML = `<p class="hint">${esc(why(e))}</p>`; return; }
if(!box.isConnected) return;
box.innerHTML = `<h2>Servers</h2>
<p class="hint">Each server sharing with the directory, by its token's name. Dropping one removes its
@@ -170,7 +170,7 @@ async function drawDirectoryAdmin(){
toast('Unblocked. It comes back with the next snapshot that has it');
}
drawDirectoryAdmin();
}catch(e){ toast(e.message, true); }
}catch(e){ toast(why(e), true); }
};
}
@@ -201,7 +201,7 @@ async function drawAccounts(){
// Demoting yourself takes this page away; go back to the app rather than stay on a page
// the server no longer answers. Only on success: a refusal's toast has to stay readable.
if(u.name === me?.name){ location.href = '/'; return; }
}catch(e){ toast(e.message, true); }
}catch(e){ toast(why(e), true); }
drawAccounts(); // on a refusal, this puts the checkbox back where the server left it
};
for(const row of $$('#accounts [data-id]')){
@@ -218,7 +218,7 @@ async function drawAccounts(){
await api('/api/users', {method: 'POST', body: JSON.stringify({
name: $('#uname').value, password: $('#upass').value, admin: $('#uadmin').checked})});
toast('Added'); drawAccounts();
}catch(e){ toast(e.message, true); } // keep what was typed
}catch(e){ toast(why(e), true); } // keep what was typed
};
}
@@ -281,7 +281,7 @@ async function pollLog(){
}else if(!logLines.length){ drawLog(); }
}catch(e){
const box = $('#logbox');
if(box) box.innerHTML = `<p class="empty">Lost contact with the daemon: ${esc(e.message)}</p>`;
if(box) box.innerHTML = `<p class="empty">Lost contact with the daemon: ${esc(why(e))}</p>`;
}
}
function visibleLog(){