The signed release showed only its background colour and never started the sidecar. Tauri's freezePrototype freezes Object.prototype before the bundle runs; d3-color and d3-format (under the visx charts) assign `constructor` / `toString` on plain objects while loading, which throws on a frozen prototype, so the bundle stopped before React drew anything. The saved state was not the cause. - build/freeze-safe.ts: Vite plugin that rewrites those assignments in dependencies into a helper that defines the property when the frozen prototype would refuse it - error boundaries for the window, each screen and each app tab (Copy details, Reload, Reset saved state with a backup); public/boot.js shows the same panel when the bundle fails or the window stays empty - logs/host.log (start, saved state, sidecar start/stop, panics) and logs/webview.log (log_webview), rotated, home as ~, keys, tokens and e-mail addresses replaced - state.json `version` 2 with an explicit 1 -> 2 migration (original kept as state.json.v1.bak), per-entry tolerant parsing, partial settings keep their fields, unreadable files kept aside - folders that are gone: "Folder not found" with Locate... (project_locate) / Remove; portfolio reads skip them - tools/desktop-boot-check.ts: the built window with the release CSP and the frozen prototype, a mocked host from the state fixtures (empty, D1 with folders gone, D3) and the real sidecar, through every screen; in bun run ci, the Forgejo CI workflow and the macOS release
77 lines
3.5 KiB
TypeScript
77 lines
3.5 KiB
TypeScript
// Uncaught errors of the window: one place that turns them into a readable report, sends it to
|
|
// <app data>/logs/webview.log (the host sanitizes again and rate-limits), and offers it for "Copy details".
|
|
// public/boot.js covers the time before React runs (a bundle that fails to load); from the first render on, React's
|
|
// root error callbacks, the error boundaries and the window handlers below report here.
|
|
import { api } from '../api';
|
|
|
|
export interface CrashReport { message: string; detail: string }
|
|
|
|
let home: string | null = null;
|
|
let version = '';
|
|
/** Shown as "~" in reports, like everywhere in the window. */
|
|
export function setCrashContext(h: string | null, v: string): void { home = h; version = v; }
|
|
|
|
const tilde = (s: string): string => {
|
|
const h = home?.replace(/[\\/]+$/, '');
|
|
return h && h.length > 1 ? s.split(h).join('~') : s;
|
|
};
|
|
|
|
export function errorMessage(e: unknown): string {
|
|
if (e instanceof Error) return `${e.name}: ${e.message}`;
|
|
if (typeof e === 'string') return e;
|
|
if (e && typeof e === 'object' && 'message' in e && typeof (e as { message: unknown }).message === 'string') return (e as { message: string }).message;
|
|
try { return JSON.stringify(e) ?? String(e); } catch { return String(e); }
|
|
}
|
|
|
|
/** Message plus a details block (where, version, time, stack, React component stack) with the home folder as ~. */
|
|
export function describe(where: string, e: unknown, componentStack?: string | null): CrashReport {
|
|
const message = tilde(errorMessage(e));
|
|
const lines = [
|
|
`storebound desktop ${version || '?'} · ${where}`,
|
|
`time: ${new Date().toISOString()}`,
|
|
'',
|
|
message,
|
|
];
|
|
const stack = e instanceof Error && e.stack ? e.stack : '';
|
|
if (stack) lines.push('', stack.trimEnd());
|
|
if (componentStack) lines.push('', 'component stack:', componentStack.trim());
|
|
return { message, detail: tilde(lines.join('\n')) };
|
|
}
|
|
|
|
const recent = new Map<string, number>();
|
|
/** Logs one report (the same message at most once every 10 s). Never throws. */
|
|
export function report(where: string, e: unknown, componentStack?: string | null, level: 'error' | 'warn' = 'error'): CrashReport {
|
|
const r = describe(where, e, componentStack);
|
|
const key = `${where}|${r.message}`;
|
|
const now = Date.now();
|
|
if ((recent.get(key) ?? 0) + 10_000 < now) {
|
|
recent.set(key, now);
|
|
if (recent.size > 100) recent.clear();
|
|
try { api.logWebview(level, `${where}: ${r.message}`, r.detail).catch(() => {}); } catch { /* no host (tests, a browser) */ }
|
|
}
|
|
return r;
|
|
}
|
|
|
|
/** window.onerror and unhandled promise rejections, after React took over from public/boot.js. */
|
|
export function installGlobalHandlers(): void {
|
|
// public/boot.js stops logging on its own from here
|
|
(window as { __storeboundCrashHandlers?: boolean }).__storeboundCrashHandlers = true;
|
|
window.addEventListener('error', ev => { report('window.onerror', ev.error ?? ev.message); });
|
|
window.addEventListener('unhandledrejection', ev => { report('unhandledrejection', ev.reason, null, 'warn'); });
|
|
}
|
|
|
|
/** Clipboard first, then the old selection way (the webview may refuse clipboard access). True when copied. */
|
|
export async function copyText(text: string): Promise<boolean> {
|
|
try { await navigator.clipboard.writeText(text); return true; } catch { /* fall through */ }
|
|
try {
|
|
const ta = document.createElement('textarea');
|
|
ta.value = text;
|
|
ta.setAttribute('readonly', '');
|
|
ta.className = 'sr';
|
|
document.body.appendChild(ta);
|
|
ta.select();
|
|
const ok = document.execCommand('copy');
|
|
ta.remove();
|
|
return ok;
|
|
} catch { return false; }
|
|
}
|