storebound/cli/lib/crash-hints.ts

22 lines
1.3 KiB
TypeScript

// "Likely cause" hints for known crash signatures, shared by `storebound health` and the desktop Health tab.
// Only entries verified in a real app (or documented by the library itself) go here: a wrong hint costs more than none.
export interface CrashHint { id: string; cause: string; fix: string }
interface Rule extends CrashHint { match: (text: string) => boolean }
const RULES: Rule[] = [
{
id: 'capacitor-permission-states-npe',
match: x => /NullPointerException/.test(x) && /com\.getcapacitor\.Bridge\.getPermissionStates/.test(x),
cause: 'A Capacitor plugin\'s checkPermissions() (for example FirebaseMessaging) ran during an activity transition (focus / visibilitychange while the app resumes or rotates), when the bridge has no activity.',
fix: 'Ask for the permission state only when App.getState() says active, the page is visible and the app has been active for a short delay (e.g. 500 ms); do not call checkPermissions() from focus / visibilitychange handlers directly.',
},
];
/** The hint for an issue's text (cause, location, top frames), or null. */
export function crashHint(...texts: (string | undefined | null)[]): CrashHint | null {
const text = texts.filter(Boolean).join('\n');
const r = RULES.find(x => x.match(text));
return r ? { id: r.id, cause: r.cause, fix: r.fix } : null;
}