Skip to content

Commit

Permalink
ignore deprecations internally
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Aug 19, 2024
1 parent 4ae6696 commit 06a4a5f
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 5 deletions.
6 changes: 4 additions & 2 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:async';

import 'package:meta/meta.dart';
import 'hint.dart';

import 'hint.dart';
import 'hub.dart';
import 'metrics/metric.dart';
import 'metrics/metrics_aggregator.dart';
Expand All @@ -13,8 +13,8 @@ import 'protocol/sentry_feedback.dart';
import 'scope.dart';
import 'sentry.dart';
import 'sentry_client.dart';
import 'sentry_user_feedback.dart';
import 'sentry_options.dart';
import 'sentry_user_feedback.dart';
import 'tracing.dart';

/// Hub adapter to make Integrations testable
Expand Down Expand Up @@ -118,7 +118,9 @@ class HubAdapter implements Hub {
ISentrySpan? getSpan() => Sentry.currentHub.getSpan();

@override
// ignore: deprecated_member_use_from_same_package
Future<void> captureUserFeedback(SentryUserFeedback userFeedback) =>
// ignore: deprecated_member_use_from_same_package
Sentry.captureUserFeedback(userFeedback);

@override
Expand Down
1 change: 1 addition & 0 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class NoOpHub implements Hub {
SentryId.empty();

@override
// ignore: deprecated_member_use_from_same_package
Future<void> captureUserFeedback(SentryUserFeedback userFeedback) async {}

@override

Check warning on line 103 in dart/lib/src/noop_hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/noop_hub.dart#L103

Added line #L103 was not covered by tests
Expand Down
1 change: 1 addition & 0 deletions dart/lib/src/noop_sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class NoOpSentryClient implements SentryClient {
SentryId.empty();

@override
// ignore: deprecated_member_use_from_same_package
Future<void> captureUserFeedback(SentryUserFeedback userFeedback) async {}

@override
Expand Down
5 changes: 3 additions & 2 deletions dart/lib/src/sentry_envelope_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import 'dart:convert';
import 'client_reports/client_report.dart';
import 'metrics/metric.dart';
import 'protocol.dart';
import 'utils.dart';
import 'sentry_attachment/sentry_attachment.dart';
import 'sentry_item_type.dart';
import 'sentry_envelope_item_header.dart';
import 'sentry_item_type.dart';
import 'sentry_user_feedback.dart';
import 'utils.dart';

/// Item holding header information and JSON encoded data.
class SentryEnvelopeItem {
Expand Down Expand Up @@ -46,6 +46,7 @@ class SentryEnvelopeItem {
}

/// Create a [SentryEnvelopeItem] which sends [SentryUserFeedback].
@Deprecated('Will be removed in a future version.')
factory SentryEnvelopeItem.fromUserFeedback(SentryUserFeedback feedback) {
final cachedItem =
_CachedItem(() async => utf8JsonEncoder.convert(feedback.toJson()));
Expand Down
3 changes: 3 additions & 0 deletions dart/test/mocks/mock_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class MockHub with NoSuchMethodProvider implements Hub {
List<CaptureMessageCall> captureMessageCalls = [];
List<AddBreadcrumbCall> addBreadcrumbCalls = [];
List<SentryClient?> bindClientCalls = [];

// ignore: deprecated_member_use_from_same_package
List<SentryUserFeedback> userFeedbackCalls = [];
List<CaptureTransactionCall> captureTransactionCalls = [];
List<CaptureMetricsCall> captureMetricsCalls = [];
Expand Down Expand Up @@ -133,6 +135,7 @@ class MockHub with NoSuchMethodProvider implements Hub {
}

@override
// ignore: deprecated_member_use_from_same_package
Future<void> captureUserFeedback(SentryUserFeedback userFeedback) async {
userFeedbackCalls.add(userFeedback);
}
Expand Down
3 changes: 3 additions & 0 deletions dart/test/mocks/mock_sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class MockSentryClient with NoSuchMethodProvider implements SentryClient {
List<CaptureMessageCall> captureMessageCalls = [];
List<CaptureEnvelopeCall> captureEnvelopeCalls = [];
List<CaptureTransactionCall> captureTransactionCalls = [];

// ignore: deprecated_member_use_from_same_package
List<SentryUserFeedback> userFeedbackCalls = [];
List<CaptureFeedbackCall> captureFeedbackCalls = [];
List<Map<int, Iterable<Metric>>> captureMetricsCalls = [];
Expand Down Expand Up @@ -73,6 +75,7 @@ class MockSentryClient with NoSuchMethodProvider implements SentryClient {
}

@override
// ignore: deprecated_member_use_from_same_package
Future<void> captureUserFeedback(SentryUserFeedback userFeedback) async {
userFeedbackCalls.add(userFeedback);
}
Expand Down
6 changes: 6 additions & 0 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1655,12 +1655,14 @@ void main() {
final client = fixture.getSut(eventProcessor: DropAllEventProcessor());

final id = SentryId.newId();
// ignore: deprecated_member_use_from_same_package
final feedback = SentryUserFeedback(
eventId: id,
comments: 'this is awesome',
email: '[email protected]',
name: 'Rockstar Developer',
);
// ignore: deprecated_member_use_from_same_package
await client.captureUserFeedback(feedback);

expect(fixture.recorder.flushCalled, true);
Expand All @@ -1676,12 +1678,14 @@ void main() {
final client = fixture.getSut(eventProcessor: DropAllEventProcessor());

final id = SentryId.newId();
// ignore: deprecated_member_use_from_same_package
final feedback = SentryUserFeedback(
eventId: id,
comments: 'this is awesome',
email: '[email protected]',
name: 'Rockstar Developer',
);
// ignore: deprecated_member_use_from_same_package
await client.captureUserFeedback(feedback);

final envelope = fixture.transport.envelopes.first;
Expand Down Expand Up @@ -1844,10 +1848,12 @@ void main() {
test('user feedback envelope contains dsn', () async {
final client = fixture.getSut();
final event = SentryEvent();
// ignore: deprecated_member_use_from_same_package
final feedback = SentryUserFeedback(
eventId: event.eventId,
name: 'test',
);
// ignore: deprecated_member_use_from_same_package
await client.captureUserFeedback(feedback);

final capturedEnvelope = (fixture.transport).envelopes.first;
Expand Down
2 changes: 2 additions & 0 deletions dart/test/sentry_envelope_item_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ void main() {
});

test('fromUserFeedback', () async {
// ignore: deprecated_member_use_from_same_package
final userFeedback = SentryUserFeedback(
eventId: SentryId.newId(),
name: 'name',
comments: 'comments',
email: 'email');
// ignore: deprecated_member_use_from_same_package
final sut = SentryEnvelopeItem.fromUserFeedback(userFeedback);

final expectedData = utf8.encode(jsonEncode(
Expand Down
3 changes: 3 additions & 0 deletions dart/test/sentry_envelope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,20 @@ void main() {

test('fromUserFeedback', () async {
final eventId = SentryId.newId();
// ignore: deprecated_member_use_from_same_package
final userFeedback = SentryUserFeedback(
eventId: eventId, name: 'name', email: 'email', comments: 'comments');
final sdkVersion =
SdkVersion(name: 'fixture-name', version: 'fixture-version');
// ignore: deprecated_member_use_from_same_package
final sut = SentryEnvelope.fromUserFeedback(
userFeedback,
sdkVersion,
dsn: fakeDsn,
);

final expectedEnvelopeItem =
// ignore: deprecated_member_use_from_same_package
SentryEnvelopeItem.fromUserFeedback(userFeedback);

expect(sut.header.eventId, eventId);
Expand Down
21 changes: 21 additions & 0 deletions dart/test/sentry_user_feedback_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import 'mocks.dart';
import 'mocks/mock_transport.dart';

void main() {
// ignore: deprecated_member_use_from_same_package
group('$SentryUserFeedback', () {
final id = SentryId.newId();

// ignore: deprecated_member_use_from_same_package
final feedback = SentryUserFeedback(
eventId: id,
comments: 'this is awesome',
Expand Down Expand Up @@ -45,6 +47,7 @@ void main() {

test('copyWith', () {
final id = SentryId.newId();
// ignore: deprecated_member_use_from_same_package
final feedback = SentryUserFeedback(
eventId: id,
comments: 'this is awesome',
Expand All @@ -68,17 +71,21 @@ void main() {

test('disallow empty id', () {
final id = SentryId.empty();
// ignore: deprecated_member_use_from_same_package
expect(() => SentryUserFeedback(eventId: id),
throwsA(isA<AssertionError>()));
});
});

// ignore: deprecated_member_use_from_same_package
group('$SentryUserFeedback to envelops', () {
test('to envelope', () {
// ignore: deprecated_member_use_from_same_package
final feedback = SentryUserFeedback(
eventId: SentryId.newId(),
name: 'test',
);
// ignore: deprecated_member_use_from_same_package
final envelope = SentryEnvelope.fromUserFeedback(
feedback,
SdkVersion(name: 'a', version: 'b'),
Expand All @@ -95,9 +102,11 @@ void main() {
});
});

// ignore: deprecated_member_use_from_same_package
test('sending $SentryUserFeedback', () async {
final fixture = Fixture();
final sut = fixture.getSut();
// ignore: deprecated_member_use_from_same_package
await sut.captureUserFeedback(SentryUserFeedback(
eventId: SentryId.newId(),
name: 'test',
Expand All @@ -106,18 +115,23 @@ void main() {
expect(fixture.transport.envelopes.length, 1);
});

// ignore: deprecated_member_use_from_same_package
test('cannot create $SentryUserFeedback with empty id', () async {
expect(
// ignore: deprecated_member_use_from_same_package
() => SentryUserFeedback(eventId: const SentryId.empty()),
throwsA(isA<AssertionError>()),
);
});

// ignore: deprecated_member_use_from_same_package
test('do not send $SentryUserFeedback when disabled', () async {
final fixture = Fixture();
final sut = fixture.getSut();
await sut.close();
// ignore: deprecated_member_use_from_same_package
await sut.captureUserFeedback(
// ignore: deprecated_member_use_from_same_package
SentryUserFeedback(
eventId: SentryId.newId(),
name: 'test',
Expand All @@ -127,10 +141,12 @@ void main() {
expect(fixture.transport.envelopes.length, 0);
});

// ignore: deprecated_member_use_from_same_package
test('do not send $SentryUserFeedback with empty id', () async {
final fixture = Fixture();
final sut = fixture.getSut();
await sut.close();
// ignore: deprecated_member_use_from_same_package
await sut.captureUserFeedback(
SentryUserFeedbackWithoutAssert(
eventId: SentryId.empty(),
Expand All @@ -147,7 +163,9 @@ void main() {
final sut = Hub(options);

await expectLater(() async {
// ignore: deprecated_member_use_from_same_package
await sut.captureUserFeedback(
// ignore: deprecated_member_use_from_same_package
SentryUserFeedback(eventId: SentryId.newId(), name: 'name'),
);
}, returnsNormally);
Expand All @@ -168,6 +186,7 @@ class Fixture {
// You cannot create an instance of SentryUserFeedback with an empty id.
// In order to test that UserFeedback with an empty id is not sent
// we need to implement it and remove the assert.
// ignore: deprecated_member_use_from_same_package
class SentryUserFeedbackWithoutAssert implements SentryUserFeedback {
SentryUserFeedbackWithoutAssert({
required this.eventId,
Expand Down Expand Up @@ -204,12 +223,14 @@ class SentryUserFeedbackWithoutAssert implements SentryUserFeedback {
}

@override
// ignore: deprecated_member_use_from_same_package
SentryUserFeedback copyWith({
SentryId? eventId,
String? name,
String? email,
String? comments,
}) {
// ignore: deprecated_member_use_from_same_package
return SentryUserFeedback(
eventId: eventId ?? this.eventId,
name: name ?? this.name,
Expand Down
1 change: 1 addition & 0 deletions flutter/example/integration_test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void main() {
testWidgets('setup sentry and capture user feedback', (tester) async {
await setupSentryAndApp(tester);

// ignore: deprecated_member_use_from_same_package
final feedback = SentryUserFeedback(

Check notice on line 89 in flutter/example/integration_test/integration_test.dart

View workflow job for this annotation

GitHub Actions / analyze / analyze

'SentryUserFeedback' is deprecated and shouldn't be used. Will be removed in a future version. Use [SentryFeedback] instead.

Try replacing the use of the deprecated member with the replacement. See https://dart.dev/diagnostics/deprecated_member_use to learn more about this problem.
eventId: SentryId.newId(),
name: 'fixture-name',
Expand Down
4 changes: 3 additions & 1 deletion flutter/example/lib/user_feedback_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ignore_for_file: library_private_types_in_public_api

import 'package:flutter/material.dart';

import 'package:sentry_flutter/sentry_flutter.dart';

class UserFeedbackDialog extends StatefulWidget {
Expand Down Expand Up @@ -86,6 +85,7 @@ class _UserFeedbackDialogState extends State<UserFeedbackDialog> {
ElevatedButton(
key: const ValueKey('sentry_submit_feedback_button'),
onPressed: () async {
// ignore: deprecated_member_use
final feedback = SentryUserFeedback(
eventId: widget.eventId,
comments: commentController.text,
Expand All @@ -108,7 +108,9 @@ class _UserFeedbackDialogState extends State<UserFeedbackDialog> {
);
}

// ignore: deprecated_member_use
Future<void> _submitUserFeedback(SentryUserFeedback feedback) {
// ignore: deprecated_member_use
return (widget.hub ?? HubAdapter()).captureUserFeedback(feedback);
}
}
Expand Down

0 comments on commit 06a4a5f

Please sign in to comment.