Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Make hint non-nullable in BeforeSendCallback and BeforeBreadcrumbCall…
…back
  • Loading branch information
denrase committed Jul 31, 2023
commit 06729c6a992cd04d3f1e84a380b1145fddf78136
8 changes: 4 additions & 4 deletions dart/lib/src/hint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'sentry_attachment/sentry_attachment.dart';
/// Example:
///
/// ```dart
/// options.beforeSend = (event, {hint}) {
/// final syntheticException = hint?.get(TypeCheckHint.syntheticException);
/// options.beforeSend = (event, hint) {
/// final syntheticException = hint.get(TypeCheckHint.syntheticException);
/// if (syntheticException is FlutterErrorDetails) {
/// // Do something with hint data
/// }
Expand All @@ -28,14 +28,14 @@ import 'sentry_attachment/sentry_attachment.dart';
/// ```dart
/// import 'dart:convert';
///
/// options.beforeSend = (event, {hint}) {
/// options.beforeSend = (event, hint) {
/// final text = 'This event should not be sent happen in prod. Investigate.';
/// final textAttachment = SentryAttachment.fromIntList(
/// utf8.encode(text),
/// 'event_info.txt',
/// contentType: 'text/plain',
/// );
/// hint?.attachments.add(textAttachment);
/// hint.attachments.add(textAttachment);
/// return event;
/// };
/// ```
Expand Down
8 changes: 4 additions & 4 deletions dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Scope {

Scope(this._options);

Breadcrumb? _addBreadCrumbSync(Breadcrumb breadcrumb, {Hint? hint}) {
Breadcrumb? _addBreadCrumbSync(Breadcrumb breadcrumb, Hint hint) {
// bail out if maxBreadcrumbs is zero
if (_options.maxBreadcrumbs == 0) {
return null;
Expand All @@ -155,7 +155,7 @@ class Scope {
try {
processedBreadcrumb = _options.beforeBreadcrumb!(
processedBreadcrumb,
hint: hint,
hint,
);
if (processedBreadcrumb == null) {
_options.logger(
Expand Down Expand Up @@ -189,7 +189,7 @@ class Scope {

/// Adds a breadcrumb to the breadcrumbs queue
Future<void> addBreadcrumb(Breadcrumb breadcrumb, {Hint? hint}) async {
final addedBreadcrumb = _addBreadCrumbSync(breadcrumb, hint: hint);
final addedBreadcrumb = _addBreadCrumbSync(breadcrumb, hint ?? Hint());
if (addedBreadcrumb != null) {
await _callScopeObservers((scopeObserver) async =>
await scopeObserver.addBreadcrumb(addedBreadcrumb));
Expand Down Expand Up @@ -429,7 +429,7 @@ class Scope {
}

for (final breadcrumb in List.from(_breadcrumbs)) {
clone._addBreadCrumbSync(breadcrumb);
clone._addBreadCrumbSync(breadcrumb, Hint());
}

for (final eventProcessor in List.from(_eventProcessors)) {
Expand Down
12 changes: 6 additions & 6 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SentryClient {

preparedEvent = await _runBeforeSend(
preparedEvent,
hint: hint,
hint,
);

// dropped by beforeSend
Expand Down Expand Up @@ -312,7 +312,7 @@ class SentryClient {
}

preparedTransaction =
await _runBeforeSend(preparedTransaction) as SentryTransaction?;
await _runBeforeSend(preparedTransaction, Hint()) as SentryTransaction?;

// dropped by beforeSendTransaction
if (preparedTransaction == null) {
Expand Down Expand Up @@ -354,9 +354,9 @@ class SentryClient {
void close() => _options.httpClient.close();

Future<SentryEvent?> _runBeforeSend(
SentryEvent event, {
Hint? hint,
}) async {
SentryEvent event,
Hint hint,
) async {
SentryEvent? eventOrTransaction = event;

final beforeSend = _options.beforeSend;
Expand All @@ -373,7 +373,7 @@ class SentryClient {
eventOrTransaction = e;
}
} else if (beforeSend != null) {
final e = beforeSend(event, hint: hint);
final e = beforeSend(event, hint);
if (e is Future<SentryEvent?>) {
eventOrTransaction = await e;
} else {
Expand Down
12 changes: 6 additions & 6 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ class SentryOptions {
/// This function is called with an SDK specific event object and can return a modified event
/// object or nothing to skip reporting the event
typedef BeforeSendCallback = FutureOr<SentryEvent?> Function(
SentryEvent event, {
Hint? hint,
});
SentryEvent event,
Hint hint,
);

/// This function is called with an SDK specific transaction object and can return a modified transaction
/// object or nothing to skip reporting the transaction
Expand All @@ -458,9 +458,9 @@ typedef BeforeSendTransactionCallback = FutureOr<SentryTransaction?> Function(
/// This function is called with an SDK specific breadcrumb object before the breadcrumb is added
/// to the scope. When nothing is returned from the function, the breadcrumb is dropped
typedef BeforeBreadcrumbCallback = Breadcrumb? Function(
Breadcrumb? breadcrumb, {
Hint? hint,
});
Breadcrumb? breadcrumb,
Hint hint,
);

/// Used to provide timestamp for logging.
typedef ClockProvider = DateTime Function();
Expand Down
22 changes: 11 additions & 11 deletions dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,9 @@ void main() {
final sut = fixture.getSut(
scopeObserver: fixture.mockScopeObserver,
beforeBreadcrumbCallback: (
Breadcrumb? breadcrumb, {
Breadcrumb? breadcrumb,
Hint? hint,
}) {
) {
return breadcrumb?.copyWith(message: "modified");
},
);
Expand Down Expand Up @@ -690,9 +690,9 @@ void main() {

final sut = fixture.getSut(
beforeBreadcrumbCallback: (
Breadcrumb? breadcrumb, {
Hint? hint,
}) {
Breadcrumb? breadcrumb,
Hint hint,
) {
throw exception;
},
debug: true);
Expand All @@ -714,9 +714,9 @@ void main() {

final sut = fixture.getSut(
beforeBreadcrumbCallback: (
Breadcrumb? breadcrumb, {
Hint? hint,
}) {
Breadcrumb? breadcrumb,
Hint hint,
) {
if (numberOfBeforeBreadcrumbCalls > 0) {
throw exception;
}
Expand Down Expand Up @@ -777,11 +777,11 @@ class Fixture {

EventProcessor get processor => DropAllEventProcessor();

Breadcrumb? beforeBreadcrumbCallback(Breadcrumb? breadcrumb, {Hint? hint}) =>
Breadcrumb? beforeBreadcrumbCallback(Breadcrumb? breadcrumb, Hint hint) =>
null;

Breadcrumb? beforeBreadcrumbMutateCallback(Breadcrumb? breadcrumb,
{Hint? hint}) =>
Breadcrumb? beforeBreadcrumbMutateCallback(
Breadcrumb? breadcrumb, Hint hint) =>
breadcrumb?.copyWith(message: 'new message');

void mockLogger(
Expand Down
17 changes: 8 additions & 9 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ void main() {

test('thrown error is handled', () async {
final exception = Exception("before send exception");
final beforeSendCallback = (SentryEvent event, {Hint? hint}) {
final beforeSendCallback = (SentryEvent event, Hint hint) {
throw exception;
};

Expand Down Expand Up @@ -1598,9 +1598,9 @@ Future<Map<String, dynamic>> transactionFromEnvelope(
}

SentryEvent? beforeSendCallbackDropEvent(
SentryEvent event, {
Hint? hint,
}) =>
SentryEvent event,
Hint hint,
) =>
null;

SentryTransaction? beforeSendTransactionCallbackDropEvent(
Expand All @@ -1609,9 +1609,9 @@ SentryTransaction? beforeSendTransactionCallbackDropEvent(
null;

Future<SentryEvent?> asyncBeforeSendCallbackDropEvent(
SentryEvent event, {
SentryEvent event,
Hint? hint,
}) async {
) async {
await Future.delayed(Duration(milliseconds: 200));
return null;
}
Expand All @@ -1622,7 +1622,7 @@ Future<SentryTransaction?> asyncBeforeSendTransactionCallbackDropEvent(
return null;
}

SentryEvent? beforeSendCallback(SentryEvent event, {Hint? hint}) {
SentryEvent? beforeSendCallback(SentryEvent event, Hint hint) {
return event
..tags!.addAll({'theme': 'material'})
// ignore: deprecated_member_use_from_same_package
Expand Down Expand Up @@ -1698,8 +1698,7 @@ class Fixture {
return client;
}

Future<SentryEvent?> droppingBeforeSend(SentryEvent event,
{Hint? hint}) async {
Future<SentryEvent?> droppingBeforeSend(SentryEvent event, Hint hint) async {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion flutter/example/integration_test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void main() {
class Fixture {
SentryEvent? sentEvent;

FutureOr<SentryEvent?> beforeSend(SentryEvent event, {Hint? hint}) async {
FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async {
sentEvent = event;
return event;
}
Expand Down
1 change: 0 additions & 1 deletion flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import 'dart:async';
import 'dart:convert';
import 'dart:io' show Platform;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down