@@ -14,6 +14,20 @@ object CrashScrub {
1414 var ownPackagePrefixes: List <String > = listOf (" dev.ide." )
1515 private const val MAX_FRAMES = 30
1616
17+ /* *
18+ * Platform/library packages that are safe to name when a crash has NONE of our own frames anywhere (neither
19+ * the exception nor its cause chain). These hold no user data — the user's program runs on the interpreter
20+ * VM, never as real host JVM frames — so a `kotlin.collections.CollectionsKt.first` or
21+ * `androidx.compose.*` frame is a class+method+line of the framework, not PII. Without this, a crash buried
22+ * entirely in framework code reports an EMPTY `frames` and is untriageable (we saw a large `NoSuchElement`/
23+ * `ClassCast` cluster with nothing to act on). Bounded to a few top frames of the deepest cause.
24+ */
25+ private val platformPackagePrefixes: List <String > = listOf (
26+ " androidx." , " android." , " java." , " javax." , " kotlin." , " kotlinx." ,
27+ " org.jetbrains." , " com.google." , " com.android." , " dalvik." , " sun." , " libcore." ,
28+ )
29+ private const val MAX_FALLBACK_FRAMES = 8
30+
1731 /* * `{exception: "Type <- CauseType <- …", frames: "Class.method:line\n…"}` — scrubbed. */
1832 fun scrub (t : Throwable ): Map <String , String > = mapOf (
1933 " exception" to exceptionChain(t),
@@ -50,12 +64,18 @@ object CrashScrub {
5064 // A deep framework crash (Compose runtime, Android looper) can bury the first of OUR frames past the
5165 // cap — or entirely, with our code only on the cause chain — leaving an untriageable report (we saw a
5266 // large share of crashes with no own frame at all). Guarantee the deepest own frame anywhere in the
53- // exception's own trace or its causes, so every crash pins to a call site we can act on.
54- if (! anyOwn) deepestOwnFrame(t)?.let { out .add(it) }
67+ // exception's own trace or its causes, so every crash pins to a call site we can act on. If there is no
68+ // own frame ANYWHERE, fall back to the deepest cause's top platform frames so the crash site is still
69+ // visible instead of an empty report.
70+ if (! anyOwn) {
71+ val own = deepestOwnFrame(t)
72+ if (own != null ) out .add(own) else out .addAll(platformFallbackFrames(t))
73+ }
5574 return out .joinToString(" \n " )
5675 }
5776
5877 private fun isOwn (f : StackTraceElement ) = ownPackagePrefixes.any { f.className.startsWith(it) }
78+ private fun isPlatform (f : StackTraceElement ) = platformPackagePrefixes.any { f.className.startsWith(it) }
5979 private fun frame (f : StackTraceElement ) = " ${f.className} .${f.methodName} :${f.lineNumber} "
6080
6181 /* * The first own frame found walking the exception and its cause chain (cycle-guarded); null if none. */
@@ -68,4 +88,22 @@ object CrashScrub {
6888 }
6989 return null
7090 }
91+
92+ /* *
93+ * When no own frame exists anywhere, the top platform frames of the deepest cause (the actual origin) — so
94+ * a crash that lives entirely in framework/stdlib code still reports WHERE it threw. Privacy-safe: only
95+ * recognized platform packages, class+method+line, no messages. Empty if the trace has no platform frame.
96+ */
97+ private fun platformFallbackFrames (t : Throwable ): List <String > {
98+ val chain = ArrayList <Throwable >()
99+ val seen = HashSet <Throwable >()
100+ var cur: Throwable ? = t
101+ while (cur != null && seen.add(cur)) { chain.add(cur); cur = cur.cause }
102+ for (e in chain.asReversed()) { // deepest cause first
103+ val frames = e.stackTrace.asSequence().filter { isPlatform(it) }.take(MAX_FALLBACK_FRAMES )
104+ .map { frame(it) }.toList()
105+ if (frames.isNotEmpty()) return frames
106+ }
107+ return emptyList()
108+ }
71109}
0 commit comments