Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid attempting to flush unhandled error reports in same session #902

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## TBD

* Avoid attempting to flush unhandled error reports in same session
[#902](/~https://github.com/bugsnag/bugsnag-android/pull/902)

## 5.0.0 (2020-04-22)

__This version contains many breaking changes__. It is part of an effort to unify our notifier
Expand Down
1 change: 1 addition & 0 deletions bugsnag-android-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ID>MaxLineLength:InternalEventPayloadDelegateTest.kt$InternalEventPayloadDelegateTest$`when`(deviceDataCollector.generateDeviceWithState(ArgumentMatchers.anyLong())).thenReturn(generateDeviceWithState())</ID>
<ID>MaxLineLength:SessionTest.kt$SessionTest$assertFalse(Session(File("150450000000053a27e4e-967c-4e5c-91be-2e86f2eb7cdc.json"), Notifier(), NoopLogger).isV2Payload)</ID>
<ID>ProtectedMemberInFinalClass:ConfigInternal.kt$ConfigInternal$protected val plugins = mutableSetOf&lt;Plugin&gt;()</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun isAnr(event: Event): Boolean</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun shouldDiscardClass(): Boolean</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun updateSeverityInternal(severity: Severity)</ID>
<ID>ProtectedMemberInFinalClass:PluginClient.kt$PluginClient$protected val plugins: Set&lt;Plugin&gt;</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void deliver(@NonNull Event event) {
}

if (event.isUnhandled()) {
cacheEvent(event, true);
// should only send unhandled errors if they don't terminate the process (i.e. ANRs)
cacheEvent(event, event.impl.isAnr(event));
} else {
deliverPayloadAsync(event, eventPayload);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ internal class EventInternal @JvmOverloads internal constructor(
}
}

protected fun isAnr(event: Event): Boolean {
val errors = event.errors
var errorClass: String? = null
if (errors.isNotEmpty()) {
val error = errors[0]
errorClass = error.errorClass
}
return "ANR" == errorClass
}

@Throws(IOException::class)
override fun toStream(writer: JsonStream) {
// Write error basics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.bugsnag.android

import com.bugsnag.android.BugsnagTestUtils.generateImmutableConfig
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,19 @@ public void testGetSetErrors() {
assertEquals(testRuntimeException.getClass().getName(), errors.get(0).getErrorClass());
assertEquals(testRuntimeException.getMessage(), errors.get(0).getErrorMessage());
}

@Test
public void testIsAnr() {
RuntimeException exc = new RuntimeException("Something went wrong");
Event event = new Event(exc, config, handledState, NoopLogger.INSTANCE);
assertFalse(event.impl.isAnr(event));

// simulate ANR
event.getErrors().get(0).setErrorClass("ANR");
assertTrue(event.impl.isAnr(event));

// clear all errors
event.getErrors().clear();
assertFalse(event.impl.isAnr(event));
}
}
3 changes: 2 additions & 1 deletion tests/features/stackoverflow.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Feature: Reporting Stack overflow

Scenario: Stack Overflow sends
When I run "StackOverflowScenario"
When I run "StackOverflowScenario" and relaunch the app
And I configure Bugsnag for "StackOverflowScenario"
And I wait to receive a request
And the request is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the payload field "events" is an array with 1 elements
Expand Down