Skip to content

Commit 6baf63e

Browse files
Wrap onDiscard callback in a try-catch and fix docstring
1 parent 1b53c4e commit 6baf63e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public class SentryOptions {
179179
*/
180180
private @Nullable BeforeBreadcrumbCallback beforeBreadcrumb;
181181

182-
/** Invoked when some payload sent from the SDK is dropped before consumed by Sentry, */
182+
/** Invoked when some data from the SDK is dropped before being consumed by Sentry */
183183
private @Nullable OnDiscardCallback onDiscard;
184184

185185
/** The cache dir. path for caching offline events */

sentry/src/main/java/io/sentry/clientreport/ClientReportRecorder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,16 @@ private void recordLostEventInternal(
125125
final ClientReportKey key = new ClientReportKey(reason, category);
126126
storage.addCount(key, countToAdd);
127127
if (options.getOnDiscard() != null) {
128-
options.getOnDiscard().execute(reason, category, countToAdd);
128+
try {
129+
options.getOnDiscard().execute(reason, category, countToAdd);
130+
} catch (Throwable e) {
131+
options
132+
.getLogger()
133+
.log(
134+
SentryLevel.ERROR,
135+
"The onDiscard callback threw an exception. It will be added as breadcrumb and continue.",
136+
e);
137+
}
129138
}
130139
}
131140

0 commit comments

Comments
 (0)