feat(debug): App-Crash-Reporting via RVS — Logs in der Diagnostic-UI
Stefan ist unterwegs, ADB-Zugriff nicht moeglich. Loesung: die App
loggt ihre eigenen Crashes via RVS, Bridge sammelt sie in
/shared/logs/app.log, Diagnostic-Server liefert sie als JSON.
Damit braucht's keinen ADB mehr — Crashes sind sofort vom Browser
(oder Claude per curl) lesbar.
Komponenten:
1. App components/ErrorBoundary.tsx
- React-ErrorBoundary fuer kritische Sections
- componentDidCatch → reportAppError (RVS-Send)
- UI zeigt Error-Box statt White-Screen + Reset-Button
2. App services/logger.ts
- reportAppError(scope, message, stack) → rvs.send('app_log', ...)
- installGlobalCrashReporter() haengt sich an ErrorUtils.setGlobalHandler
UND HermesInternal.enablePromiseRejectionTracker — fangt sowohl
ungefangene Errors als auch unhandled Promise-Rejections
- Konsole bleibt parallel aktiv (damit ADB im Dev-Build weiter
was sieht)
3. App App.tsx: installGlobalCrashReporter() im useEffect zusammen
mit initLogger.
4. App ChatScreen.tsx:
- Inbox-Modal mit ErrorBoundary umschlossen (scope: InboxModal,
onReset schliesst Modal)
- MemoryDetailModal mit ErrorBoundary umschlossen
- DetailModal wird nur noch konditional gerendert (memoryDetailId
!= null) statt immer visible-toggle — vermeidet potentielles
Modal-Stacking-Problem
5. RVS server.js: ALLOWED_TYPES += "app_log"
6. Bridge aria_bridge.py:
- elif msg_type == "app_log": haengt eine Zeile an
/shared/logs/app.log (JSONL, jedes Item {ts, platform, level,
scope, message, stack})
- Plus log.info Hinweis fuer das normale Bridge-Log
7. Diagnostic server.js:
- GET /api/app-log[?limit=N] → letzte N Eintraege als JSON
- POST /api/app-log/clear → log-Datei loeschen
Workflow zum Debuggen des Inbox-Crashes:
Stefan rebuilded App → drueckt Inbox → ErrorBoundary fangt den
Crash (oder Global-Handler bei ungefangenem Error) → reportAppError
→ RVS → Bridge schreibt nach /shared/logs/app.log → Stefan
oder Claude rufen GET /api/app-log auf → sehen Stacktrace.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { Platform } from 'react-native';
|
||||
import rvs from './rvs';
|
||||
|
||||
export const VERBOSE_LOGGING_KEY = 'aria_verbose_logging';
|
||||
|
||||
@@ -39,3 +41,77 @@ export function setVerboseLogging(verbose: boolean): void {
|
||||
applyState();
|
||||
AsyncStorage.setItem(VERBOSE_LOGGING_KEY, String(verbose)).catch(() => {});
|
||||
}
|
||||
|
||||
// ─── App-Crash-Reporting via RVS ────────────────────────────────────
|
||||
//
|
||||
// Wenn die App crasht — egal ob React-Render-Fehler (ErrorBoundary) oder
|
||||
// ungefangener JS-Error (ErrorUtils-Handler) — schicken wir den Crash
|
||||
// als RVS-Message vom Typ "app_log" an die Bridge. Die schreibt in
|
||||
// /shared/logs/app.log, sodass wir/Diagnostic die Crashes mitlesen
|
||||
// koennen ohne ADB.
|
||||
|
||||
interface AppErrorEvent {
|
||||
scope: string;
|
||||
message: string;
|
||||
stack?: string;
|
||||
level?: 'error' | 'warn' | 'info';
|
||||
}
|
||||
|
||||
let _reportingInstalled = false;
|
||||
|
||||
/** Schickt einen App-Fehler via RVS an die Bridge. */
|
||||
export function reportAppError(ev: AppErrorEvent): void {
|
||||
try {
|
||||
rvs.send('app_log' as any, {
|
||||
ts: Date.now(),
|
||||
platform: Platform.OS,
|
||||
level: ev.level || 'error',
|
||||
scope: ev.scope,
|
||||
message: ev.message,
|
||||
stack: (ev.stack || '').slice(0, 8000),
|
||||
});
|
||||
} catch {
|
||||
// RVS noch nicht connected — Fehler geht im console weiter.
|
||||
}
|
||||
// Plus lokal: console.error, damit Stefan's adb (wenn doch mal verfuegbar)
|
||||
// den Crash sieht.
|
||||
console.error(`[app-error scope=${ev.scope}]`, ev.message, '\n', ev.stack || '');
|
||||
}
|
||||
|
||||
/** Installiert einen globalen JS-Error-Handler der ungefangene Errors via
|
||||
* RVS an die Bridge schickt. Beim App-Start aufrufen. */
|
||||
export function installGlobalCrashReporter(): void {
|
||||
if (_reportingInstalled) return;
|
||||
_reportingInstalled = true;
|
||||
try {
|
||||
const g: any = global as any;
|
||||
const prev = g.ErrorUtils?.getGlobalHandler?.();
|
||||
g.ErrorUtils?.setGlobalHandler?.((err: any, isFatal: boolean) => {
|
||||
reportAppError({
|
||||
scope: isFatal ? 'global-fatal' : 'global-nonfatal',
|
||||
message: (err && err.message) || String(err),
|
||||
stack: err && err.stack,
|
||||
});
|
||||
// Original-Handler weiterhin aufrufen damit React-Native das System-
|
||||
// Crash-Overlay zeigt (im Dev-Build) bzw. in Production sauber stirbt.
|
||||
if (typeof prev === 'function') {
|
||||
try { prev(err, isFatal); } catch {}
|
||||
}
|
||||
});
|
||||
// unhandled Promise-Rejections — manche RN-Versionen haben das nicht
|
||||
// automatisch im ErrorUtils.
|
||||
g.HermesInternal?.enablePromiseRejectionTracker?.({
|
||||
allRejections: true,
|
||||
onUnhandled: (id: number, err: any) => {
|
||||
reportAppError({
|
||||
scope: 'promise-unhandled',
|
||||
level: 'warn',
|
||||
message: (err && err.message) || String(err),
|
||||
stack: err && err.stack,
|
||||
});
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
// ErrorUtils nicht da → nix machen
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user