Skip to content

Commit 5acdb18

Browse files
fix(flutter): Allow empty associatedEventId (#4108)
SentryFeedbackForm asserted that associatedEventId is never SentryId.empty(), but Hub.captureMessage/captureEvent return the empty id whenever the capture is not sent (network error, disabled hub, beforeSend drop). Opening the form with that id crashed debug and profile builds. Treat an empty id the same as null (no association) instead. Fixes #4042 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 54f7a7a commit 5acdb18

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎packages/flutter/lib/src/feedback/sentry_feedback_form.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import '../utils/internal_logger.dart';
1313

1414
/// A form for submitting user feedback to Sentry.
1515
class SentryFeedbackForm extends StatefulWidget {
16+
/// An empty [associatedEventId] (e.g. returned when the original event
17+
/// could not be captured) is treated as no association.
1618
SentryFeedbackForm({
1719
super.key,
18-
this.associatedEventId,
20+
SentryId? associatedEventId,
1921
this.screenshot,
2022
@internal Hub? hub,
21-
}) : assert(associatedEventId != const SentryId.empty()),
23+
}) : associatedEventId = associatedEventId == const SentryId.empty()
24+
? null
25+
: associatedEventId,
2226
_hub = hub ?? HubAdapter() {
2327
assert(
2428
_hub.options is SentryFlutterOptions,

‎packages/flutter/test/feedback/sentry_feedback_form_test.dart‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,48 @@ void main() {
514514
),
515515
).called(1);
516516
});
517+
518+
testWidgets(
519+
'submits feedback without association when associatedEventId is empty',
520+
(tester) async {
521+
await fixture.pumpFeedbackForm(
522+
tester,
523+
(hub) => SentryFeedbackForm(
524+
hub: hub,
525+
associatedEventId: const SentryId.empty(),
526+
),
527+
);
528+
529+
when(
530+
fixture.hub.captureFeedback(
531+
any,
532+
hint: anyNamed('hint'),
533+
withScope: anyNamed('withScope'),
534+
),
535+
).thenAnswer(
536+
(_) async => SentryId.fromId('1988bb1b6f0d4c509e232f0cb9aaeaea'),
537+
);
538+
539+
await tester.enterText(
540+
find.byKey(ValueKey('sentry_feedback_message_textfield')),
541+
"fixture-message",
542+
);
543+
await tester.tap(find.text('Send Bug Report'));
544+
await tester.pumpAndSettle();
545+
546+
verify(
547+
fixture.hub.captureFeedback(
548+
argThat(
549+
predicate<SentryFeedback>(
550+
(feedback) => feedback.associatedEventId == null,
551+
),
552+
),
553+
hint: anyNamed('hint'),
554+
withScope: anyNamed('withScope'),
555+
),
556+
).called(1);
557+
},
558+
);
517559
});
518560

519561
group('$SentryFeedbackForm localization', () {

0 commit comments

Comments
 (0)