Skip to content

Commit 5edad4a

Browse files
markushiclaude
andcommitted
ref(feedback): Narrow the screenshot attachment catches to the expected types
AGENTS.md now forbids new catch (Throwable). Replaces the three broad catches with the types the guarded code can actually throw: - launch() documents ActivityNotFoundException and the registry throws IllegalStateException for an unregistered launcher - the ContentResolver calls cross into the provider process, where Binder can only deliver the exceptions Parcel marshals, all RuntimeException Fatal throwables now propagate because they are never caught, so ExceptionUtils.rethrowIfFatal is no longer needed here. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6794390 commit 5edad4a

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎sentry-android-core/src/main/java/io/sentry/android/core/SentryUserFeedbackForm.java‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.app.AlertDialog;
55
import android.app.Application;
6+
import android.content.ActivityNotFoundException;
67
import android.content.ContentResolver;
78
import android.content.Context;
89
import android.content.ContextWrapper;
@@ -30,7 +31,6 @@
3031
import io.sentry.protocol.Feedback;
3132
import io.sentry.protocol.SentryId;
3233
import io.sentry.protocol.User;
33-
import io.sentry.util.ExceptionUtils;
3434
import io.sentry.util.FileUtils;
3535
import io.sentry.util.LoadClass;
3636
import java.io.IOException;
@@ -229,13 +229,12 @@ protected void onCreate(Bundle savedInstanceState) {
229229
if (screenshotPicker != null) {
230230
try {
231231
screenshotPicker.launch();
232-
} catch (Throwable t) {
233-
ExceptionUtils.rethrowIfFatal(t);
234-
// e.g. no photo picker on the device, or the host activity is already gone
232+
} catch (ActivityNotFoundException | IllegalStateException e) {
233+
// No photo picker on the device, or the launcher is no longer registered
235234
Sentry.getCurrentScopes()
236235
.getOptions()
237236
.getLogger()
238-
.log(SentryLevel.ERROR, "Failed to launch the screenshot picker.", t);
237+
.log(SentryLevel.ERROR, "Failed to launch the screenshot picker.", e);
239238
}
240239
}
241240
} else {
@@ -527,13 +526,14 @@ private void maybeAddImageAttachment(final @NotNull Hint hint) {
527526
mime,
528527
"event.attachment",
529528
false));
530-
} catch (Throwable t) {
531-
ExceptionUtils.rethrowIfFatal(t);
532-
// e.g. the read permission for the picked Uri was revoked in the meantime
529+
} catch (RuntimeException e) {
530+
// The ContentResolver call crosses into the provider's process, so any failure there arrives
531+
// as one of the exceptions Binder can marshal, e.g. a SecurityException once the read
532+
// permission for the picked Uri was revoked
533533
Sentry.getCurrentScopes()
534534
.getOptions()
535535
.getLogger()
536-
.log(SentryLevel.ERROR, "Failed to attach image to feedback.", t);
536+
.log(SentryLevel.ERROR, "Failed to attach image to feedback.", e);
537537
}
538538
}
539539

@@ -548,15 +548,14 @@ private static long getUriSize(
548548
return cursor.getLong(sizeIndex);
549549
}
550550
}
551-
} catch (Throwable t) {
552-
ExceptionUtils.rethrowIfFatal(t);
551+
} catch (RuntimeException e) {
553552
options
554553
.getLogger()
555554
.log(
556555
SentryLevel.WARNING,
557556
"Unable to determine the size of the selected screenshot, the attachment size limit "
558557
+ "is applied when the feedback is captured.",
559-
t);
558+
e);
560559
}
561560
return -1;
562561
}

0 commit comments

Comments
 (0)