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

Fix: Do not crash when event processors throw a lower level Throwable class #1800

Merged
merged 6 commits into from
Nov 11, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Feat: Add `graphql-java` instrumentation (#1777)
* Fix: Do not crash when event processors throw a lower level Throwable class (#1800)
* Fix: ActivityFramesTracker does not throw if Activity has no observers (#1799)

## 5.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.sentry.android.core.ActivityLifecycleIntegration.UI_LOAD_OP;

import io.sentry.EventProcessor;
import io.sentry.SentryEvent;
import io.sentry.SpanContext;
import io.sentry.protocol.MeasurementValue;
import io.sentry.protocol.SentryId;
Expand Down Expand Up @@ -32,6 +33,22 @@ final class PerformanceAndroidEventProcessor implements EventProcessor {
Objects.requireNonNull(activityFramesTracker, "ActivityFramesTracker is required");
}

/**
* Returns the event itself
*
* @param event the SentryEvent the SentryEvent
* @param hint the Hint the Hint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confusing 🤪

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, it was auto-generated, didn't realize the confusion :(

* @return returns the event itself
*/
@Override
@Nullable
public SentryEvent process(@NotNull SentryEvent event, @Nullable Object hint) {
// that's only necessary because on newer versions of Unity, if not overriding this method, it's
// throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably
// compilation mismatch.
return event;
}

@Override
public synchronized @NotNull SentryTransaction process(
@NotNull SentryTransaction transaction, @Nullable Object hint) {
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private SentryEvent processEvent(
for (final EventProcessor processor : eventProcessors) {
try {
event = processor.process(event, hint);
} catch (Exception e) {
} catch (Throwable e) {
options
.getLogger()
.log(
Expand Down Expand Up @@ -235,7 +235,7 @@ private SentryTransaction processTransaction(
for (final EventProcessor processor : eventProcessors) {
try {
transaction = processor.process(transaction, hint);
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have other places in the codebase we should make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe yes...

} catch (Throwable e) {
options
.getLogger()
.log(
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import java.io.IOException
import java.io.InputStreamReader
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException
import java.lang.RuntimeException
import java.nio.charset.Charset
import java.util.Arrays
import java.util.UUID
Expand Down Expand Up @@ -1299,7 +1298,7 @@ class SentryClientTest {
private fun eventProcessorThrows(): EventProcessor {
return object : EventProcessor {
override fun process(event: SentryEvent, hint: Any?): SentryEvent? {
throw RuntimeException()
throw Throwable()
}
}
}
Expand Down