fix(mobile): Persist crash diagnostics before runtime fatals #4033
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -0,0 +27,21 @@27+ // file IO on the startup path.28+ setTimeout(() => {29+ reportAndPrunePreviousCrashes();30+ }, 0);31+}32+33+function persistCrashRecord(error: unknown): void {34+ const directory = new Directory(Paths.document, CRASH_LOG_DIRECTORY);35+ directory.create({ idempotent: true, intermediates: true });36+ const cause = error instanceof Error ? error : null;37+ const record = {38+ capturedAt: new Date().toISOString(),39+ isFatal: true,40+ message: cause?.message ?? String(error),41+ name: cause?.name ?? null,42+ stack: cause?.stack ?? null,43+ };44+ crashSequence += 1;45+ const file = new File(directory, `crash-${Date.now()}-${crashSequence}.json`);46+ file.create({ intermediates: true, overwrite: true });47+ file.write(JSON.stringify(record, null, 2));@@ -0,0 +50,21 @@50+function reportAndPrunePreviousCrashes(): void {51+ try {52+ const directory = new Directory(Paths.document, CRASH_LOG_DIRECTORY);53+ if (!directory.exists) {54+ return;55+ }56+ const files = directory57+ .list()58+ .filter(59+ (entry): entry is File =>60+ entry instanceof File && entry.name.startsWith("crash-") && entry.name.endsWith(".json"),61+ )62+ .sort((a, b) => a.name.localeCompare(b.name));63+ for (const file of files.slice(-REPORTED_ON_LAUNCH_COUNT)) {64+ try {65+ console.warn(`[crash-log] previous fatal JS error (${file.name}):`, file.textSync());66+ } catch {67+ // Skip unreadable records.68+ }69+ }70+ for (const file of files.slice(0, Math.max(0, files.length - MAX_PERSISTED_CRASH_LOGS))) {
- @@ -0,0 +20,21 @@20+ } catch {21+ // Never let the logger mask the original error.22+ }23+ }24+ previousHandler(error, isFatal);25+ });26+ // Deferred so install (which runs before the app module graph) does no27+ // file IO on the startup path.28+ setTimeout(() => {29+ reportAndPrunePreviousCrashes();30+ }, 0);31+}32+33+function persistCrashRecord(error: unknown): void {34+ const directory = new Directory(Paths.document, CRASH_LOG_DIRECTORY);35+ directory.create({ idempotent: true, intermediates: true });36+ const cause = error instanceof Error ? error : null;37+ const record = {38+ capturedAt: new Date().toISOString(),39+ isFatal: true,40+ message: cause?.message ?? String(error),
juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Sign in to join this conversation.





No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
d10b04a4-a67b-4a65-9045-01724df43daf📥 Commits
Reviewing files that changed from the base of the PR and between 65fbd78700ac4369b4333cf55548dc35ee42d479 and 4d520ba87589bbec7f8909db0fafd50eb0ee4324.
📒 Files selected for processing: 6
apps/mobile/index.tsapps/mobile/src/features/diagnostics/SettingsDiagnosticsRouteScreen.tsxapps/mobile/src/features/diagnostics/crash-log-model.test.tsapps/mobile/src/features/diagnostics/crash-log-model.tsapps/mobile/src/lib/crashLog.tsdocs/user/install.mdLimit details: You’ve used all 10 included reviews currently available.
📝 Walkthrough
The mobile app now saves fatal JavaScript errors and combines them with startup crash records in Settings → Diagnostics. The diagnostics screen remains available when startup-log reading fails. The install guide describes the saved records and report contents.
Changes: Mobile crash logging and diagnostics
apps/mobile/src/lib/crashLog.ts,apps/mobile/src/lib/installCrashLog.ts,apps/mobile/index.tsapps/mobile/src/features/diagnostics/crash-log-model.ts,apps/mobile/src/features/diagnostics/SettingsDiagnosticsRouteScreen.tsx,apps/mobile/src/features/diagnostics/crash-log-model.test.tsdocs/user/install.mdPriority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
Possibly related PRs
Suggested labels:
📱 Native Change,size:LSuggested reviewers:
maria-rcksMerge Risk: ⚪ Minimal · up to
4d520No actionable issue remains from this review. Native end-to-end validation is still outstanding, but it does not establish a merge-blocking defect.
Pre-merge checks:
4
Full details: Description check
Explanation
The description is detailed and covers the problem, implementation, verification results, UI evidence, limitations, scope, and agent attribution. It does not use the template headings, and it does not clearly identify an approval comment or explain an approval exemption, but the required information is mostly present.
✨ Finishing Touches
🧪 Generate unit tests (beta)