@@ -249,29 +249,7 @@ public static SentryId captureEnvelopeNonTerminating(final @NotNull byte[] envel
249249 final @ NotNull EnvelopeEventState eventState = eventStateOf (envelope , serializer );
250250
251251 if (eventState != EnvelopeEventState .NONE ) {
252- scopes .configureScope (
253- scope -> {
254- // the write stays inside the callback so the mutation and the persist are one
255- // critical section. Persisting outside it lets a concurrent caller's older snapshot
256- // land last and drop the unhandled marker.
257- scope .withSession (
258- session -> {
259- if (session != null ) {
260- final boolean updated =
261- eventState == EnvelopeEventState .UNHANDLED
262- ? session .recordNonTerminatingUnhandledError ()
263- : session .update (null , null , true , null );
264- if (updated && options .getEnvelopeDiskCache () instanceof EnvelopeCache ) {
265- ((EnvelopeCache ) options .getEnvelopeDiskCache ())
266- .persistCurrentSession (session );
267- }
268- } else {
269- options
270- .getLogger ()
271- .log (INFO , "Session is null on captureEnvelopeNonTerminating" );
272- }
273- });
274- });
252+ updateSessionNonTerminating (eventState == EnvelopeEventState .UNHANDLED );
275253 }
276254
277255 return scopes .captureEnvelope (envelope );
@@ -281,6 +259,35 @@ public static SentryId captureEnvelopeNonTerminating(final @NotNull byte[] envel
281259 return null ;
282260 }
283261
262+ /**
263+ * Mutates and persists the current session for a non-terminating hybrid error. The write stays
264+ * inside {@code withSession} so the mutation and the persist are one critical section. Persisting
265+ * outside it lets a concurrent caller's older snapshot land last and drop the unhandled marker.
266+ *
267+ * @param crashed {@code true} if the error was unhandled ({@code mechanism.handled=false})
268+ */
269+ private static void updateSessionNonTerminating (final boolean crashed ) {
270+ final @ NotNull IScopes scopes = ScopesAdapter .getInstance ();
271+ final @ NotNull SentryOptions options = scopes .getOptions ();
272+ scopes .configureScope (
273+ scope -> {
274+ scope .withSession (
275+ session -> {
276+ if (session != null ) {
277+ final boolean updated =
278+ crashed
279+ ? session .recordNonTerminatingUnhandledError ()
280+ : session .update (null , null , true , null );
281+ if (updated && options .getEnvelopeDiskCache () instanceof EnvelopeCache ) {
282+ ((EnvelopeCache ) options .getEnvelopeDiskCache ()).persistCurrentSession (session );
283+ }
284+ } else {
285+ options .getLogger ().log (INFO , "Session is null on updateSessionNonTerminating" );
286+ }
287+ });
288+ });
289+ }
290+
284291 /** What the events inside an envelope amount to, from the session's point of view. */
285292 private enum EnvelopeEventState {
286293 /** No event carried an exception. */
0 commit comments