From 60fba54e061e6e7f8b995423e8bca360887bf89c Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 3 Oct 2022 11:28:42 +0200 Subject: [PATCH 01/18] dont call apprunner in runzonedguarded if onError is supported --- dart/lib/src/sentry.dart | 39 +- dart/test/sentry_test.dart | 25 + flutter/lib/src/sentry_flutter.dart | 33 +- flutter/test/mocks.mocks.dart | 1142 +++++++------------------ flutter/test/sentry_flutter_test.dart | 287 +++++-- flutter/test/sentry_flutter_util.dart | 56 +- 6 files changed, 627 insertions(+), 955 deletions(-) diff --git a/dart/lib/src/sentry.dart b/dart/lib/src/sentry.dart index e2733711e3..4af920d333 100644 --- a/dart/lib/src/sentry.dart +++ b/dart/lib/src/sentry.dart @@ -36,6 +36,7 @@ class Sentry { static Future init( OptionsConfiguration optionsConfiguration, { AppRunner? appRunner, + bool callAppRunnerInRunZonedGuarded = true, @internal SentryOptions? options, }) async { final sentryOptions = options ?? SentryOptions(); @@ -56,7 +57,7 @@ class Sentry { throw ArgumentError('DSN is required.'); } - await _init(sentryOptions, appRunner); + await _init(sentryOptions, appRunner, callAppRunnerInRunZonedGuarded); } static Future _initDefaultValues( @@ -96,7 +97,8 @@ class Sentry { } /// Initializes the SDK - static Future _init(SentryOptions options, AppRunner? appRunner) async { + static Future _init(SentryOptions options, AppRunner? appRunner, + bool callAppRunnerInRunZonedGuarded) async { if (isEnabled) { options.logger( SentryLevel.warning, @@ -113,21 +115,26 @@ class Sentry { // execute integrations after hub being enabled if (appRunner != null) { - var runIntegrationsAndAppRunner = () async { - final integrations = - options.integrations.where((i) => i is! RunZonedGuardedIntegration); - await _callIntegrations(integrations, options); + if (callAppRunnerInRunZonedGuarded) { + var runIntegrationsAndAppRunner = () async { + final integrations = options.integrations + .where((i) => i is! RunZonedGuardedIntegration); + await _callIntegrations(integrations, options); + await appRunner(); + }; + + final runZonedGuardedIntegration = + RunZonedGuardedIntegration(runIntegrationsAndAppRunner); + options.addIntegrationByIndex(0, runZonedGuardedIntegration); + + // RunZonedGuardedIntegration will run other integrations and appRunner + // runZonedGuarded so all exception caught in the error handler are + // handled + await runZonedGuardedIntegration(HubAdapter(), options); + } else { + await _callIntegrations(options.integrations, options); await appRunner(); - }; - - final runZonedGuardedIntegration = - RunZonedGuardedIntegration(runIntegrationsAndAppRunner); - options.addIntegrationByIndex(0, runZonedGuardedIntegration); - - // RunZonedGuardedIntegration will run other integrations and appRunner - // runZonedGuarded so all exception caught in the error handler are - // handled - await runZonedGuardedIntegration(HubAdapter(), options); + } } else { await _callIntegrations(options.integrations, options); } diff --git a/dart/test/sentry_test.dart b/dart/test/sentry_test.dart index ea07988980..0e949ffc2f 100644 --- a/dart/test/sentry_test.dart +++ b/dart/test/sentry_test.dart @@ -284,6 +284,31 @@ void main() { }); }); + test('should complete when appRunner is not called in runZonedGuarded', + () async { + final completer = Completer(); + var completed = false; + + final init = Sentry.init( + (options) { + options.dsn = fakeDsn; + }, + appRunner: () => completer.future, + callAppRunnerInRunZonedGuarded: false, + ).whenComplete(() => completed = true); + + await Future(() { + // We make the expectation only after all microtasks have completed, + // that Sentry.init might have scheduled. + expect(completed, false); + }); + + completer.complete(); + await init; + + expect(completed, true); + }); + test('options.environment debug', () async { final sentryOptions = SentryOptions(dsn: fakeDsn) ..platformChecker = FakePlatformChecker.debugMode(); diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 94962bec56..28ad68ac3a 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -1,10 +1,12 @@ import 'dart:async'; +import 'dart:ui'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:sentry/sentry.dart'; +import '../sentry_flutter.dart'; import 'event_processor/android_platform_exception_event_processor.dart'; import 'native_scope_observer.dart'; import 'sentry_native.dart'; @@ -45,27 +47,26 @@ mixin SentryFlutter { final native = SentryNative(); native.setNativeChannel(nativeChannel); + final wrapper = PlatformDispatcherWrapper(PlatformDispatcher.instance); + final isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); + // first step is to install the native integration and set default values, // so we are able to capture future errors. final defaultIntegrations = _createDefaultIntegrations( - packageLoader, - channel, - flutterOptions, - ); + packageLoader, channel, flutterOptions, isOnErrorSupported); for (final defaultIntegration in defaultIntegrations) { flutterOptions.addIntegration(defaultIntegration); } await _initDefaultValues(flutterOptions, channel); - - await Sentry.init( - (options) async { - await optionsConfiguration(options as SentryFlutterOptions); - }, - appRunner: appRunner, - // ignore: invalid_use_of_internal_member - options: flutterOptions, - ); + + await Sentry.init((options) async { + await optionsConfiguration(options as SentryFlutterOptions); + }, + appRunner: appRunner, + // ignore: invalid_use_of_internal_member + options: flutterOptions, + callAppRunnerInRunZonedGuarded: !isOnErrorSupported); } static Future _initDefaultValues( @@ -96,11 +97,17 @@ mixin SentryFlutter { PackageLoader packageLoader, MethodChannel channel, SentryFlutterOptions options, + bool isOnErrorSupported, ) { final integrations = []; final platformChecker = options.platformChecker; final platform = platformChecker.platform; + // Use PlatformDispatcher.onError instead of zones. + if (isOnErrorSupported) { + integrations.add(OnErrorIntegration()); + } + // Will call WidgetsFlutterBinding.ensureInitialized() before all other integrations. integrations.add(WidgetsFlutterBindingIntegration()); diff --git a/flutter/test/mocks.mocks.dart b/flutter/test/mocks.mocks.dart index 9bce2502a0..7ce8cfe919 100644 --- a/flutter/test/mocks.mocks.dart +++ b/flutter/test/mocks.mocks.dart @@ -1,11 +1,10 @@ -// Mocks generated by Mockito 5.3.1 from annotations +// Mocks generated by Mockito 5.2.0 from annotations // in sentry_flutter/example/windows/flutter/ephemeral/.plugin_symlinks/sentry_flutter/example/linux/flutter/ephemeral/.plugin_symlinks/sentry_flutter/example/ios/.symlinks/plugins/sentry_flutter/test/mocks.dart. // Do not manually edit this file. -// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i6; -import 'package:flutter/src/services/binary_messenger.dart' as _i5; +import 'package:flutter/src/services/binding.dart' as _i5; import 'package:flutter/src/services/message_codec.dart' as _i4; import 'package:flutter/src/services/platform_channel.dart' as _i9; import 'package:mockito/mockito.dart' as _i1; @@ -27,101 +26,26 @@ import 'mocks.dart' as _i12; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class -// ignore_for_file: invalid_use_of_internal_member -class _FakeSentrySpanContext_0 extends _i1.SmartFake - implements _i2.SentrySpanContext { - _FakeSentrySpanContext_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeSentrySpanContext_0 extends _i1.Fake + implements _i2.SentrySpanContext {} -class _FakeDateTime_1 extends _i1.SmartFake implements DateTime { - _FakeDateTime_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeDateTime_1 extends _i1.Fake implements DateTime {} -class _FakeISentrySpan_2 extends _i1.SmartFake implements _i2.ISentrySpan { - _FakeISentrySpan_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeISentrySpan_2 extends _i1.Fake implements _i2.ISentrySpan {} -class _FakeSentryTraceHeader_3 extends _i1.SmartFake - implements _i3.SentryTraceHeader { - _FakeSentryTraceHeader_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeSentryTraceHeader_3 extends _i1.Fake + implements _i3.SentryTraceHeader {} -class _FakeMethodCodec_4 extends _i1.SmartFake implements _i4.MethodCodec { - _FakeMethodCodec_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeMethodCodec_4 extends _i1.Fake implements _i4.MethodCodec {} -class _FakeBinaryMessenger_5 extends _i1.SmartFake - implements _i5.BinaryMessenger { - _FakeBinaryMessenger_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeBinaryMessenger_5 extends _i1.Fake implements _i5.BinaryMessenger {} -class _FakeSentryOptions_6 extends _i1.SmartFake implements _i2.SentryOptions { - _FakeSentryOptions_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeSentryOptions_6 extends _i1.Fake implements _i2.SentryOptions {} -class _FakeSentryId_7 extends _i1.SmartFake implements _i3.SentryId { - _FakeSentryId_7( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeSentryId_7 extends _i1.Fake implements _i3.SentryId {} -class _FakeHub_8 extends _i1.SmartFake implements _i2.Hub { - _FakeHub_8( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} +class _FakeHub_8 extends _i1.Fake implements _i2.Hub {} /// A class which mocks [Transport]. /// @@ -133,13 +57,9 @@ class MockTransport extends _i1.Mock implements _i2.Transport { @override _i6.Future<_i3.SentryId?> send(_i7.SentryEnvelope? envelope) => - (super.noSuchMethod( - Invocation.method( - #send, - [envelope], - ), - returnValue: _i6.Future<_i3.SentryId?>.value(), - ) as _i6.Future<_i3.SentryId?>); + (super.noSuchMethod(Invocation.method(#send, [envelope]), + returnValue: Future<_i3.SentryId?>.value()) + as _i6.Future<_i3.SentryId?>); } /// A class which mocks [SentryTracer]. @@ -151,246 +71,107 @@ class MockSentryTracer extends _i1.Mock implements _i8.SentryTracer { } @override - String get name => (super.noSuchMethod( - Invocation.getter(#name), - returnValue: '', - ) as String); + String get name => + (super.noSuchMethod(Invocation.getter(#name), returnValue: '') as String); @override - set name(String? _name) => super.noSuchMethod( - Invocation.setter( - #name, - _name, - ), - returnValueForMissingStub: null, - ); + set name(String? _name) => super.noSuchMethod(Invocation.setter(#name, _name), + returnValueForMissingStub: null); @override _i3.SentryTransactionNameSource get transactionNameSource => - (super.noSuchMethod( - Invocation.getter(#transactionNameSource), - returnValue: _i3.SentryTransactionNameSource.custom, - ) as _i3.SentryTransactionNameSource); + (super.noSuchMethod(Invocation.getter(#transactionNameSource), + returnValue: _i3.SentryTransactionNameSource.custom) + as _i3.SentryTransactionNameSource); @override set transactionNameSource( _i3.SentryTransactionNameSource? _transactionNameSource) => super.noSuchMethod( - Invocation.setter( - #transactionNameSource, - _transactionNameSource, - ), - returnValueForMissingStub: null, - ); - @override - _i2.SentrySpanContext get context => (super.noSuchMethod( - Invocation.getter(#context), - returnValue: _FakeSentrySpanContext_0( - this, - Invocation.getter(#context), - ), - ) as _i2.SentrySpanContext); - @override - DateTime get startTimestamp => (super.noSuchMethod( - Invocation.getter(#startTimestamp), - returnValue: _FakeDateTime_1( - this, - Invocation.getter(#startTimestamp), - ), - ) as DateTime); - @override - Map get data => (super.noSuchMethod( - Invocation.getter(#data), - returnValue: {}, - ) as Map); - @override - bool get finished => (super.noSuchMethod( - Invocation.getter(#finished), - returnValue: false, - ) as bool); - @override - List<_i3.SentrySpan> get children => (super.noSuchMethod( - Invocation.getter(#children), - returnValue: <_i3.SentrySpan>[], - ) as List<_i3.SentrySpan>); - @override - set throwable(dynamic throwable) => super.noSuchMethod( - Invocation.setter( - #throwable, - throwable, - ), - returnValueForMissingStub: null, - ); - @override - set status(_i3.SpanStatus? status) => super.noSuchMethod( - Invocation.setter( - #status, - status, - ), - returnValueForMissingStub: null, - ); - @override - Map get tags => (super.noSuchMethod( - Invocation.getter(#tags), - returnValue: {}, - ) as Map); - @override - Map get measurements => (super.noSuchMethod( - Invocation.getter(#measurements), - returnValue: {}, - ) as Map); - @override - _i6.Future finish({ - _i3.SpanStatus? status, - DateTime? endTimestamp, - }) => - (super.noSuchMethod( - Invocation.method( - #finish, - [], - { - #status: status, - #endTimestamp: endTimestamp, - }, - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - void removeData(String? key) => super.noSuchMethod( - Invocation.method( - #removeData, - [key], - ), - returnValueForMissingStub: null, - ); - @override - void removeTag(String? key) => super.noSuchMethod( - Invocation.method( - #removeTag, - [key], - ), - returnValueForMissingStub: null, - ); - @override - void setData( - String? key, - dynamic value, - ) => - super.noSuchMethod( - Invocation.method( - #setData, - [ - key, - value, - ], - ), - returnValueForMissingStub: null, - ); - @override - void setTag( - String? key, - String? value, - ) => - super.noSuchMethod( - Invocation.method( - #setTag, - [ - key, - value, - ], - ), - returnValueForMissingStub: null, - ); - @override - _i2.ISentrySpan startChild( - String? operation, { - String? description, - DateTime? startTimestamp, - }) => + Invocation.setter(#transactionNameSource, _transactionNameSource), + returnValueForMissingStub: null); + @override + _i2.SentrySpanContext get context => + (super.noSuchMethod(Invocation.getter(#context), + returnValue: _FakeSentrySpanContext_0()) as _i2.SentrySpanContext); + @override + DateTime get startTimestamp => + (super.noSuchMethod(Invocation.getter(#startTimestamp), + returnValue: _FakeDateTime_1()) as DateTime); + @override + Map get data => (super.noSuchMethod(Invocation.getter(#data), + returnValue: {}) as Map); + @override + bool get finished => + (super.noSuchMethod(Invocation.getter(#finished), returnValue: false) + as bool); + @override + List<_i3.SentrySpan> get children => + (super.noSuchMethod(Invocation.getter(#children), + returnValue: <_i3.SentrySpan>[]) as List<_i3.SentrySpan>); + @override + set throwable(dynamic throwable) => + super.noSuchMethod(Invocation.setter(#throwable, throwable), + returnValueForMissingStub: null); + @override + set status(_i3.SpanStatus? status) => + super.noSuchMethod(Invocation.setter(#status, status), + returnValueForMissingStub: null); + @override + Map get tags => (super.noSuchMethod(Invocation.getter(#tags), + returnValue: {}) as Map); + @override + Map get measurements => + (super.noSuchMethod(Invocation.getter(#measurements), + returnValue: {}) + as Map); + @override + _i6.Future finish({_i3.SpanStatus? status, DateTime? endTimestamp}) => (super.noSuchMethod( - Invocation.method( - #startChild, - [operation], - { - #description: description, - #startTimestamp: startTimestamp, - }, - ), - returnValue: _FakeISentrySpan_2( - this, Invocation.method( - #startChild, - [operation], - { - #description: description, - #startTimestamp: startTimestamp, - }, - ), - ), - ) as _i2.ISentrySpan); + #finish, [], {#status: status, #endTimestamp: endTimestamp}), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + void removeData(String? key) => + super.noSuchMethod(Invocation.method(#removeData, [key]), + returnValueForMissingStub: null); + @override + void removeTag(String? key) => + super.noSuchMethod(Invocation.method(#removeTag, [key]), + returnValueForMissingStub: null); + @override + void setData(String? key, dynamic value) => + super.noSuchMethod(Invocation.method(#setData, [key, value]), + returnValueForMissingStub: null); + @override + void setTag(String? key, String? value) => + super.noSuchMethod(Invocation.method(#setTag, [key, value]), + returnValueForMissingStub: null); + @override + _i2.ISentrySpan startChild(String? operation, + {String? description, DateTime? startTimestamp}) => + (super.noSuchMethod( + Invocation.method(#startChild, [operation], + {#description: description, #startTimestamp: startTimestamp}), + returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan); @override _i2.ISentrySpan startChildWithParentSpanId( - _i3.SpanId? parentSpanId, - String? operation, { - String? description, - DateTime? startTimestamp, - }) => + _i3.SpanId? parentSpanId, String? operation, + {String? description, DateTime? startTimestamp}) => (super.noSuchMethod( - Invocation.method( - #startChildWithParentSpanId, - [ - parentSpanId, - operation, - ], - { - #description: description, - #startTimestamp: startTimestamp, - }, - ), - returnValue: _FakeISentrySpan_2( - this, Invocation.method( - #startChildWithParentSpanId, - [ - parentSpanId, - operation, - ], - { - #description: description, - #startTimestamp: startTimestamp, - }, - ), - ), - ) as _i2.ISentrySpan); - @override - _i3.SentryTraceHeader toSentryTrace() => (super.noSuchMethod( - Invocation.method( - #toSentryTrace, - [], - ), - returnValue: _FakeSentryTraceHeader_3( - this, - Invocation.method( - #toSentryTrace, - [], - ), - ), - ) as _i3.SentryTraceHeader); - @override - void setMeasurement( - String? name, - num? value, { - _i2.SentryMeasurementUnit? unit, - }) => + #startChildWithParentSpanId, + [parentSpanId, operation], + {#description: description, #startTimestamp: startTimestamp}), + returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan); + @override + _i3.SentryTraceHeader toSentryTrace() => + (super.noSuchMethod(Invocation.method(#toSentryTrace, []), + returnValue: _FakeSentryTraceHeader_3()) as _i3.SentryTraceHeader); + @override + void setMeasurement(String? name, num? value, + {_i2.SentryMeasurementUnit? unit}) => super.noSuchMethod( - Invocation.method( - #setMeasurement, - [ - name, - value, - ], - {#unit: unit}, - ), - returnValueForMissingStub: null, - ); + Invocation.method(#setMeasurement, [name, value], {#unit: unit}), + returnValueForMissingStub: null); } /// A class which mocks [MethodChannel]. @@ -402,81 +183,36 @@ class MockMethodChannel extends _i1.Mock implements _i9.MethodChannel { } @override - String get name => (super.noSuchMethod( - Invocation.getter(#name), - returnValue: '', - ) as String); - @override - _i4.MethodCodec get codec => (super.noSuchMethod( - Invocation.getter(#codec), - returnValue: _FakeMethodCodec_4( - this, - Invocation.getter(#codec), - ), - ) as _i4.MethodCodec); - @override - _i5.BinaryMessenger get binaryMessenger => (super.noSuchMethod( - Invocation.getter(#binaryMessenger), - returnValue: _FakeBinaryMessenger_5( - this, - Invocation.getter(#binaryMessenger), - ), - ) as _i5.BinaryMessenger); - @override - _i6.Future invokeMethod( - String? method, [ - dynamic arguments, - ]) => - (super.noSuchMethod( - Invocation.method( - #invokeMethod, - [ - method, - arguments, - ], - ), - returnValue: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future?> invokeListMethod( - String? method, [ - dynamic arguments, - ]) => + String get name => + (super.noSuchMethod(Invocation.getter(#name), returnValue: '') as String); + @override + _i4.MethodCodec get codec => (super.noSuchMethod(Invocation.getter(#codec), + returnValue: _FakeMethodCodec_4()) as _i4.MethodCodec); + @override + _i5.BinaryMessenger get binaryMessenger => + (super.noSuchMethod(Invocation.getter(#binaryMessenger), + returnValue: _FakeBinaryMessenger_5()) as _i5.BinaryMessenger); + @override + _i6.Future invokeMethod(String? method, [dynamic arguments]) => + (super.noSuchMethod(Invocation.method(#invokeMethod, [method, arguments]), + returnValue: Future.value()) as _i6.Future); + @override + _i6.Future?> invokeListMethod(String? method, + [dynamic arguments]) => (super.noSuchMethod( - Invocation.method( - #invokeListMethod, - [ - method, - arguments, - ], - ), - returnValue: _i6.Future?>.value(), - ) as _i6.Future?>); - @override - _i6.Future?> invokeMapMethod( - String? method, [ - dynamic arguments, - ]) => + Invocation.method(#invokeListMethod, [method, arguments]), + returnValue: Future?>.value()) as _i6.Future?>); + @override + _i6.Future?> invokeMapMethod(String? method, + [dynamic arguments]) => (super.noSuchMethod( - Invocation.method( - #invokeMapMethod, - [ - method, - arguments, - ], - ), - returnValue: _i6.Future?>.value(), - ) as _i6.Future?>); + Invocation.method(#invokeMapMethod, [method, arguments]), + returnValue: Future?>.value()) as _i6.Future?>); @override void setMethodCallHandler( _i6.Future Function(_i4.MethodCall)? handler) => - super.noSuchMethod( - Invocation.method( - #setMethodCallHandler, - [handler], - ), - returnValueForMissingStub: null, - ); + super.noSuchMethod(Invocation.method(#setMethodCallHandler, [handler]), + returnValueForMissingStub: null); } /// A class which mocks [SentryNative]. @@ -488,165 +224,82 @@ class MockSentryNative extends _i1.Mock implements _i10.SentryNative { } @override - set appStartEnd(DateTime? _appStartEnd) => super.noSuchMethod( - Invocation.setter( - #appStartEnd, - _appStartEnd, - ), - returnValueForMissingStub: null, - ); + set appStartEnd(DateTime? _appStartEnd) => + super.noSuchMethod(Invocation.setter(#appStartEnd, _appStartEnd), + returnValueForMissingStub: null); @override - bool get didFetchAppStart => (super.noSuchMethod( - Invocation.getter(#didFetchAppStart), - returnValue: false, - ) as bool); + bool get didFetchAppStart => + (super.noSuchMethod(Invocation.getter(#didFetchAppStart), + returnValue: false) as bool); @override void setNativeChannel(_i11.SentryNativeChannel? nativeChannel) => - super.noSuchMethod( - Invocation.method( - #setNativeChannel, - [nativeChannel], - ), - returnValueForMissingStub: null, - ); - @override - _i6.Future<_i11.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod( - Invocation.method( - #fetchNativeAppStart, - [], - ), - returnValue: _i6.Future<_i11.NativeAppStart?>.value(), - ) as _i6.Future<_i11.NativeAppStart?>); - @override - _i6.Future beginNativeFramesCollection() => (super.noSuchMethod( - Invocation.method( - #beginNativeFramesCollection, - [], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + super.noSuchMethod(Invocation.method(#setNativeChannel, [nativeChannel]), + returnValueForMissingStub: null); + @override + _i6.Future<_i11.NativeAppStart?> fetchNativeAppStart() => + (super.noSuchMethod(Invocation.method(#fetchNativeAppStart, []), + returnValue: Future<_i11.NativeAppStart?>.value()) + as _i6.Future<_i11.NativeAppStart?>); + @override + _i6.Future beginNativeFramesCollection() => + (super.noSuchMethod(Invocation.method(#beginNativeFramesCollection, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); @override _i6.Future<_i11.NativeFrames?> endNativeFramesCollection( _i3.SentryId? traceId) => (super.noSuchMethod( - Invocation.method( - #endNativeFramesCollection, - [traceId], - ), - returnValue: _i6.Future<_i11.NativeFrames?>.value(), - ) as _i6.Future<_i11.NativeFrames?>); - @override - _i6.Future setContexts( - String? key, - dynamic value, - ) => - (super.noSuchMethod( - Invocation.method( - #setContexts, - [ - key, - value, - ], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future removeContexts(String? key) => (super.noSuchMethod( - Invocation.method( - #removeContexts, - [key], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future setUser(_i3.SentryUser? sentryUser) => (super.noSuchMethod( - Invocation.method( - #setUser, - [sentryUser], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + Invocation.method(#endNativeFramesCollection, [traceId]), + returnValue: Future<_i11.NativeFrames?>.value()) + as _i6.Future<_i11.NativeFrames?>); + @override + _i6.Future setContexts(String? key, dynamic value) => + (super.noSuchMethod(Invocation.method(#setContexts, [key, value]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future removeContexts(String? key) => + (super.noSuchMethod(Invocation.method(#removeContexts, [key]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future setUser(_i3.SentryUser? sentryUser) => + (super.noSuchMethod(Invocation.method(#setUser, [sentryUser]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); @override _i6.Future addBreadcrumb(_i3.Breadcrumb? breadcrumb) => - (super.noSuchMethod( - Invocation.method( - #addBreadcrumb, - [breadcrumb], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future clearBreadcrumbs() => (super.noSuchMethod( - Invocation.method( - #clearBreadcrumbs, - [], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future setExtra( - String? key, - dynamic value, - ) => - (super.noSuchMethod( - Invocation.method( - #setExtra, - [ - key, - value, - ], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future removeExtra(String? key) => (super.noSuchMethod( - Invocation.method( - #removeExtra, - [key], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future setTag( - String? key, - String? value, - ) => - (super.noSuchMethod( - Invocation.method( - #setTag, - [ - key, - value, - ], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future removeTag(String? key) => (super.noSuchMethod( - Invocation.method( - #removeTag, - [key], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - void reset() => super.noSuchMethod( - Invocation.method( - #reset, - [], - ), - returnValueForMissingStub: null, - ); + (super.noSuchMethod(Invocation.method(#addBreadcrumb, [breadcrumb]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future clearBreadcrumbs() => + (super.noSuchMethod(Invocation.method(#clearBreadcrumbs, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future setExtra(String? key, dynamic value) => + (super.noSuchMethod(Invocation.method(#setExtra, [key, value]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future removeExtra(String? key) => + (super.noSuchMethod(Invocation.method(#removeExtra, [key]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future setTag(String? key, String? value) => + (super.noSuchMethod(Invocation.method(#setTag, [key, value]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future removeTag(String? key) => + (super.noSuchMethod(Invocation.method(#removeTag, [key]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + void reset() => super.noSuchMethod(Invocation.method(#reset, []), + returnValueForMissingStub: null); } /// A class which mocks [Hub]. @@ -658,304 +311,159 @@ class MockHub extends _i1.Mock implements _i2.Hub { } @override - _i2.SentryOptions get options => (super.noSuchMethod( - Invocation.getter(#options), - returnValue: _FakeSentryOptions_6( - this, - Invocation.getter(#options), - ), - ) as _i2.SentryOptions); - @override - bool get isEnabled => (super.noSuchMethod( - Invocation.getter(#isEnabled), - returnValue: false, - ) as bool); - @override - _i3.SentryId get lastEventId => (super.noSuchMethod( - Invocation.getter(#lastEventId), - returnValue: _FakeSentryId_7( - this, - Invocation.getter(#lastEventId), - ), - ) as _i3.SentryId); - @override - _i6.Future<_i3.SentryId> captureEvent( - _i3.SentryEvent? event, { - dynamic stackTrace, - dynamic hint, - _i2.ScopeCallback? withScope, - }) => + _i2.SentryOptions get options => + (super.noSuchMethod(Invocation.getter(#options), + returnValue: _FakeSentryOptions_6()) as _i2.SentryOptions); + @override + bool get isEnabled => + (super.noSuchMethod(Invocation.getter(#isEnabled), returnValue: false) + as bool); + @override + _i3.SentryId get lastEventId => + (super.noSuchMethod(Invocation.getter(#lastEventId), + returnValue: _FakeSentryId_7()) as _i3.SentryId); + @override + _i6.Future<_i3.SentryId> captureEvent(_i3.SentryEvent? event, + {dynamic stackTrace, dynamic hint, _i2.ScopeCallback? withScope}) => (super.noSuchMethod( - Invocation.method( - #captureEvent, - [event], - { - #stackTrace: stackTrace, - #hint: hint, - #withScope: withScope, - }, - ), - returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( - this, - Invocation.method( - #captureEvent, - [event], - { - #stackTrace: stackTrace, - #hint: hint, - #withScope: withScope, - }, - ), - )), - ) as _i6.Future<_i3.SentryId>); - @override - _i6.Future<_i3.SentryId> captureException( - dynamic throwable, { - dynamic stackTrace, - dynamic hint, - _i2.ScopeCallback? withScope, - }) => + Invocation.method(#captureEvent, [ + event + ], { + #stackTrace: stackTrace, + #hint: hint, + #withScope: withScope + }), + returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) + as _i6.Future<_i3.SentryId>); + @override + _i6.Future<_i3.SentryId> captureException(dynamic throwable, + {dynamic stackTrace, dynamic hint, _i2.ScopeCallback? withScope}) => (super.noSuchMethod( - Invocation.method( - #captureException, - [throwable], - { - #stackTrace: stackTrace, - #hint: hint, - #withScope: withScope, - }, - ), - returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( - this, - Invocation.method( - #captureException, - [throwable], - { - #stackTrace: stackTrace, - #hint: hint, - #withScope: withScope, - }, - ), - )), - ) as _i6.Future<_i3.SentryId>); - @override - _i6.Future<_i3.SentryId> captureMessage( - String? message, { - _i3.SentryLevel? level, - String? template, - List? params, - dynamic hint, - _i2.ScopeCallback? withScope, - }) => + Invocation.method(#captureException, [ + throwable + ], { + #stackTrace: stackTrace, + #hint: hint, + #withScope: withScope + }), + returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) + as _i6.Future<_i3.SentryId>); + @override + _i6.Future<_i3.SentryId> captureMessage(String? message, + {_i3.SentryLevel? level, + String? template, + List? params, + dynamic hint, + _i2.ScopeCallback? withScope}) => (super.noSuchMethod( - Invocation.method( - #captureMessage, - [message], - { - #level: level, - #template: template, - #params: params, - #hint: hint, - #withScope: withScope, - }, - ), - returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( - this, - Invocation.method( - #captureMessage, - [message], - { - #level: level, - #template: template, - #params: params, - #hint: hint, - #withScope: withScope, - }, - ), - )), - ) as _i6.Future<_i3.SentryId>); + Invocation.method(#captureMessage, [ + message + ], { + #level: level, + #template: template, + #params: params, + #hint: hint, + #withScope: withScope + }), + returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) + as _i6.Future<_i3.SentryId>); @override _i6.Future captureUserFeedback(_i2.SentryUserFeedback? userFeedback) => (super.noSuchMethod( - Invocation.method( - #captureUserFeedback, - [userFeedback], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future addBreadcrumb( - _i3.Breadcrumb? crumb, { - dynamic hint, - }) => + Invocation.method(#captureUserFeedback, [userFeedback]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future addBreadcrumb(_i3.Breadcrumb? crumb, {dynamic hint}) => (super.noSuchMethod( - Invocation.method( - #addBreadcrumb, - [crumb], - {#hint: hint}, - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - void bindClient(_i2.SentryClient? client) => super.noSuchMethod( - Invocation.method( - #bindClient, - [client], - ), - returnValueForMissingStub: null, - ); - @override - _i2.Hub clone() => (super.noSuchMethod( - Invocation.method( - #clone, - [], - ), - returnValue: _FakeHub_8( - this, - Invocation.method( - #clone, - [], - ), - ), - ) as _i2.Hub); - @override - _i6.Future close() => (super.noSuchMethod( - Invocation.method( - #close, - [], - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + Invocation.method(#addBreadcrumb, [crumb], {#hint: hint}), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + void bindClient(_i2.SentryClient? client) => + super.noSuchMethod(Invocation.method(#bindClient, [client]), + returnValueForMissingStub: null); + @override + _i2.Hub clone() => (super.noSuchMethod(Invocation.method(#clone, []), + returnValue: _FakeHub_8()) as _i2.Hub); + @override + _i6.Future close() => (super.noSuchMethod(Invocation.method(#close, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); @override _i6.FutureOr configureScope(_i2.ScopeCallback? callback) => - (super.noSuchMethod(Invocation.method( - #configureScope, - [callback], - )) as _i6.FutureOr); - @override - _i2.ISentrySpan startTransaction( - String? name, - String? operation, { - String? description, - DateTime? startTimestamp, - bool? bindToScope, - bool? waitForChildren, - Duration? autoFinishAfter, - bool? trimEnd, - _i2.OnTransactionFinish? onFinish, - Map? customSamplingContext, - }) => + (super.noSuchMethod(Invocation.method(#configureScope, [callback])) + as _i6.FutureOr); + @override + _i2.ISentrySpan startTransaction(String? name, String? operation, + {String? description, + DateTime? startTimestamp, + bool? bindToScope, + bool? waitForChildren, + Duration? autoFinishAfter, + bool? trimEnd, + _i2.OnTransactionFinish? onFinish, + Map? customSamplingContext}) => (super.noSuchMethod( - Invocation.method( - #startTransaction, - [ - name, - operation, - ], - { - #description: description, - #startTimestamp: startTimestamp, - #bindToScope: bindToScope, - #waitForChildren: waitForChildren, - #autoFinishAfter: autoFinishAfter, - #trimEnd: trimEnd, - #onFinish: onFinish, - #customSamplingContext: customSamplingContext, - }, - ), - returnValue: _i12.startTransactionShim( - name, - operation, - description: description, - startTimestamp: startTimestamp, - bindToScope: bindToScope, - waitForChildren: waitForChildren, - autoFinishAfter: autoFinishAfter, - trimEnd: trimEnd, - onFinish: onFinish, - customSamplingContext: customSamplingContext, - ), - ) as _i2.ISentrySpan); + Invocation.method(#startTransaction, [ + name, + operation + ], { + #description: description, + #startTimestamp: startTimestamp, + #bindToScope: bindToScope, + #waitForChildren: waitForChildren, + #autoFinishAfter: autoFinishAfter, + #trimEnd: trimEnd, + #onFinish: onFinish, + #customSamplingContext: customSamplingContext + }), + returnValue: _i12.startTransactionShim(name, operation, + description: description, + startTimestamp: startTimestamp, + bindToScope: bindToScope, + waitForChildren: waitForChildren, + autoFinishAfter: autoFinishAfter, + trimEnd: trimEnd, + onFinish: onFinish, + customSamplingContext: customSamplingContext)) + as _i2.ISentrySpan); @override _i2.ISentrySpan startTransactionWithContext( - _i2.SentryTransactionContext? transactionContext, { - Map? customSamplingContext, - DateTime? startTimestamp, - bool? bindToScope, - bool? waitForChildren, - Duration? autoFinishAfter, - bool? trimEnd, - _i2.OnTransactionFinish? onFinish, - }) => + _i2.SentryTransactionContext? transactionContext, + {Map? customSamplingContext, + DateTime? startTimestamp, + bool? bindToScope, + bool? waitForChildren, + Duration? autoFinishAfter, + bool? trimEnd, + _i2.OnTransactionFinish? onFinish}) => (super.noSuchMethod( - Invocation.method( - #startTransactionWithContext, - [transactionContext], - { + Invocation.method(#startTransactionWithContext, [ + transactionContext + ], { #customSamplingContext: customSamplingContext, #startTimestamp: startTimestamp, #bindToScope: bindToScope, #waitForChildren: waitForChildren, #autoFinishAfter: autoFinishAfter, #trimEnd: trimEnd, - #onFinish: onFinish, - }, - ), - returnValue: _FakeISentrySpan_2( - this, - Invocation.method( - #startTransactionWithContext, - [transactionContext], - { - #customSamplingContext: customSamplingContext, - #startTimestamp: startTimestamp, - #bindToScope: bindToScope, - #waitForChildren: waitForChildren, - #autoFinishAfter: autoFinishAfter, - #trimEnd: trimEnd, - #onFinish: onFinish, - }, - ), - ), - ) as _i2.ISentrySpan); + #onFinish: onFinish + }), + returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan); @override _i6.Future<_i3.SentryId> captureTransaction( - _i3.SentryTransaction? transaction, { - _i2.SentryTraceContextHeader? traceContext, - }) => + _i3.SentryTransaction? transaction, + {_i2.SentryTraceContextHeader? traceContext}) => (super.noSuchMethod( - Invocation.method( - #captureTransaction, - [transaction], - {#traceContext: traceContext}, - ), - returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( - this, - Invocation.method( - #captureTransaction, - [transaction], - {#traceContext: traceContext}, - ), - )), - ) as _i6.Future<_i3.SentryId>); + Invocation.method(#captureTransaction, [transaction], + {#traceContext: traceContext}), + returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) + as _i6.Future<_i3.SentryId>); @override void setSpanContext( - dynamic throwable, - _i2.ISentrySpan? span, - String? transaction, - ) => + dynamic throwable, _i2.ISentrySpan? span, String? transaction) => super.noSuchMethod( - Invocation.method( - #setSpanContext, - [ - throwable, - span, - transaction, - ], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#setSpanContext, [throwable, span, transaction]), + returnValueForMissingStub: null); } diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index 1836fa0ed7..cd84e71a22 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -4,11 +4,13 @@ import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/integrations/debug_print_integration.dart'; import 'package:sentry_flutter/src/version.dart'; import 'mocks.dart'; +import 'mocks.mocks.dart'; import 'sentry_flutter_util.dart'; /// These are the integrations which should be added on every platform. /// They don't depend on the underlying platform. final platformAgnosticIntegrations = [ + OnErrorIntegration, FlutterErrorIntegration, LoadReleaseIntegration, DebugPrintIntegration, @@ -39,111 +41,179 @@ void main() { }); test('Android', () async { + List integrations = []; + Transport transport = MockTransport(); + await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: true, + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, + appRunner: appRunner, + packageLoader: loadTestPackage, + platformChecker: getPlatformChecker(platform: MockPlatform.android()), + ); + + testTransport( + transport: transport, + hasFileSystemTransport: true, + ); + + testConfiguration( + integrations: integrations, shouldHaveIntegrations: [ ...androidIntegrations, ...nativeIntegrations, ...platformAgnosticIntegrations, ], - shouldNotHaveIntegrations: iOsAndMacOsIntegrations, - ), - appRunner: appRunner, - packageLoader: loadTestPackage, - platformChecker: getPlatformChecker(platform: MockPlatform.android()), - ); + shouldNotHaveIntegrations: iOsAndMacOsIntegrations); await Sentry.close(); }, testOn: 'vm'); test('iOS', () async { + List integrations = []; + Transport transport = MockTransport(); + await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: true, - shouldHaveIntegrations: [ - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ...platformAgnosticIntegrations, - ], - shouldNotHaveIntegrations: androidIntegrations, - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker(platform: MockPlatform.iOs()), ); + testTransport( + transport: transport, + hasFileSystemTransport: true, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: [ + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ...platformAgnosticIntegrations, + ], + shouldNotHaveIntegrations: androidIntegrations, + ); + await Sentry.close(); }, testOn: 'vm'); test('macOS', () async { + List integrations = []; + Transport transport = MockTransport(); + await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: true, - shouldHaveIntegrations: [ - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ...platformAgnosticIntegrations, - ], - shouldNotHaveIntegrations: androidIntegrations, - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker(platform: MockPlatform.macOs()), ); + testTransport( + transport: transport, + hasFileSystemTransport: true, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: [ + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ...platformAgnosticIntegrations, + ], + shouldNotHaveIntegrations: androidIntegrations, + ); + await Sentry.close(); }, testOn: 'vm'); test('Windows', () async { + List integrations = []; + Transport transport = MockTransport(); + await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: false, - shouldHaveIntegrations: platformAgnosticIntegrations, - shouldNotHaveIntegrations: [ - ...androidIntegrations, - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ], - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker(platform: MockPlatform.windows()), ); + testTransport( + transport: transport, + hasFileSystemTransport: false, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: platformAgnosticIntegrations, + shouldNotHaveIntegrations: [ + ...androidIntegrations, + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ], + ); + await Sentry.close(); }, testOn: 'vm'); test('Linux', () async { + List integrations = []; + Transport transport = MockTransport(); + await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: false, - shouldHaveIntegrations: platformAgnosticIntegrations, - shouldNotHaveIntegrations: [ - ...androidIntegrations, - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ], - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker(platform: MockPlatform.linux()), ); + testTransport( + transport: transport, + hasFileSystemTransport: false, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: platformAgnosticIntegrations, + shouldNotHaveIntegrations: [ + ...androidIntegrations, + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ], + ); + await Sentry.close(); }, testOn: 'vm'); test('Web', () async { + List integrations = []; + Transport transport = MockTransport(); + await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: false, - shouldHaveIntegrations: platformAgnosticIntegrations, - shouldNotHaveIntegrations: [ - ...androidIntegrations, - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ], - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker( @@ -152,22 +222,36 @@ void main() { ), ); + testTransport( + transport: transport, + hasFileSystemTransport: false, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: platformAgnosticIntegrations, + shouldNotHaveIntegrations: [ + ...androidIntegrations, + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ], + ); + await Sentry.close(); }); test('Web && (iOS || macOS) ', () async { + List integrations = []; + Transport transport = MockTransport(); + // Tests that iOS || macOS integrations aren't added on a browser which // runs on iOS or macOS await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: false, - shouldHaveIntegrations: platformAgnosticIntegrations, - shouldNotHaveIntegrations: [ - ...androidIntegrations, - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ], - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker( @@ -176,22 +260,36 @@ void main() { ), ); + testTransport( + transport: transport, + hasFileSystemTransport: false, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: platformAgnosticIntegrations, + shouldNotHaveIntegrations: [ + ...androidIntegrations, + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ], + ); + await Sentry.close(); }); test('Web && (macOS)', () async { + List integrations = []; + Transport transport = MockTransport(); + // Tests that iOS || macOS integrations aren't added on a browswer which // runs on iOS or macOS await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: false, - shouldHaveIntegrations: platformAgnosticIntegrations, - shouldNotHaveIntegrations: [ - ...androidIntegrations, - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ], - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker( @@ -200,21 +298,35 @@ void main() { ), ); + testTransport( + transport: transport, + hasFileSystemTransport: false, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: platformAgnosticIntegrations, + shouldNotHaveIntegrations: [ + ...androidIntegrations, + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ], + ); + await Sentry.close(); }); test('Web && Android', () async { + List integrations = []; + Transport transport = MockTransport(); + // Tests that Android integrations aren't added on an Android browswer await SentryFlutter.init( - getConfigurationTester( - hasFileSystemTransport: false, - shouldHaveIntegrations: platformAgnosticIntegrations, - shouldNotHaveIntegrations: [ - ...androidIntegrations, - ...iOsAndMacOsIntegrations, - ...nativeIntegrations, - ], - ), + (options) async { + options.dsn = fakeDsn; + integrations = options.integrations; + transport = options.transport; + }, appRunner: appRunner, packageLoader: loadTestPackage, platformChecker: getPlatformChecker( @@ -223,6 +335,21 @@ void main() { ), ); + testTransport( + transport: transport, + hasFileSystemTransport: false, + ); + + testConfiguration( + integrations: integrations, + shouldHaveIntegrations: platformAgnosticIntegrations, + shouldNotHaveIntegrations: [ + ...androidIntegrations, + ...iOsAndMacOsIntegrations, + ...nativeIntegrations, + ], + ); + await Sentry.close(); }); }); diff --git a/flutter/test/sentry_flutter_util.dart b/flutter/test/sentry_flutter_util.dart index a0fb496c02..ac437eb5d6 100644 --- a/flutter/test/sentry_flutter_util.dart +++ b/flutter/test/sentry_flutter_util.dart @@ -1,38 +1,36 @@ -import 'dart:async'; - import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/file_system_transport.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; -import 'mocks.dart'; +void testTransport({ + required Transport transport, + required hasFileSystemTransport, +}) { + expect( + transport is FileSystemTransport, + hasFileSystemTransport, + reason: '$FileSystemTransport was wrongly set', + ); +} -FutureOr Function(SentryFlutterOptions) getConfigurationTester({ +void testConfiguration({ + required Iterable integrations, required Iterable shouldHaveIntegrations, required Iterable shouldNotHaveIntegrations, - required bool hasFileSystemTransport, -}) => - (options) async { - options.dsn = fakeDsn; - - expect( - options.transport is FileSystemTransport, - hasFileSystemTransport, - reason: '$FileSystemTransport was wrongly set', - ); - - final integrations = {}; - for (var e in options.integrations) { - integrations[e.runtimeType] = integrations[e.runtimeType] ?? 0 + 1; - } +}) { + final numberOfIntegrationsByType = {}; + for (var e in integrations) { + numberOfIntegrationsByType[e.runtimeType] = + numberOfIntegrationsByType[e.runtimeType] ?? 0 + 1; + } - for (final type in shouldHaveIntegrations) { - expect(integrations, containsPair(type, 1)); - } + for (final type in shouldHaveIntegrations) { + expect(numberOfIntegrationsByType, containsPair(type, 1)); + } - shouldNotHaveIntegrations = Set.of(shouldNotHaveIntegrations) - .difference(Set.of(shouldHaveIntegrations)); - for (final type in shouldNotHaveIntegrations) { - expect(integrations, isNot(contains(type))); - } - }; + shouldNotHaveIntegrations = Set.of(shouldNotHaveIntegrations) + .difference(Set.of(shouldHaveIntegrations)); + for (final type in shouldNotHaveIntegrations) { + expect(integrations, isNot(contains(type))); + } +} From a18c5ac65109abde2539397477cbf8e8e377fae7 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 3 Oct 2022 11:29:47 +0200 Subject: [PATCH 02/18] format --- flutter/lib/src/sentry_flutter.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 28ad68ac3a..04a7d4775e 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -59,7 +59,7 @@ mixin SentryFlutter { } await _initDefaultValues(flutterOptions, channel); - + await Sentry.init((options) async { await optionsConfiguration(options as SentryFlutterOptions); }, From 93602519fc7177d9130ba57e0a14d9f5a9bcf0f1 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 3 Oct 2022 11:44:06 +0200 Subject: [PATCH 03/18] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index af26ecb4e7..ffb115eace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Use PlatformDispatcher.onError in Flutter 3.3 ([#1039](https://github.com/getsentry/sentry-dart/pull/1039)) + ## 6.11.2 ### Fixes From 1a43cf11289d94ba28ec8a1bfa72e913a9e9ee41 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 3 Oct 2022 11:58:21 +0200 Subject: [PATCH 04/18] fix analyze issues --- flutter/lib/src/sentry_flutter.dart | 3 --- flutter/test/mocks.mocks.dart | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 04a7d4775e..28b473fd86 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -5,7 +5,6 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; import 'package:package_info_plus/package_info_plus.dart'; -import 'package:sentry/sentry.dart'; import '../sentry_flutter.dart'; import 'event_processor/android_platform_exception_event_processor.dart'; import 'native_scope_observer.dart'; @@ -15,9 +14,7 @@ import 'sentry_native_channel.dart'; import 'flutter_enricher_event_processor.dart'; import 'integrations/debug_print_integration.dart'; import 'integrations/native_app_start_integration.dart'; -import 'sentry_flutter_options.dart'; -import 'default_integrations.dart'; import 'file_system_transport.dart'; import 'version.dart'; diff --git a/flutter/test/mocks.mocks.dart b/flutter/test/mocks.mocks.dart index 7ce8cfe919..b6ab0745f0 100644 --- a/flutter/test/mocks.mocks.dart +++ b/flutter/test/mocks.mocks.dart @@ -15,6 +15,7 @@ import 'package:sentry/src/sentry_tracer.dart' as _i8; import 'package:sentry_flutter/src/sentry_native.dart' as _i10; import 'package:sentry_flutter/src/sentry_native_channel.dart' as _i11; +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'mocks.dart' as _i12; // ignore_for_file: type=lint @@ -26,6 +27,8 @@ import 'mocks.dart' as _i12; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeSentrySpanContext_0 extends _i1.Fake implements _i2.SentrySpanContext {} From 34a2d4fe133ac9a0d339a00e8caa0413bc2e049e Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 3 Oct 2022 14:04:05 +0200 Subject: [PATCH 05/18] use BindingUtils.getWidgetsBindingInstance() to access platform dispatcher --- flutter/lib/src/sentry_flutter.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 28b473fd86..229745f035 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -1,11 +1,11 @@ import 'dart:async'; -import 'dart:ui'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; import 'package:package_info_plus/package_info_plus.dart'; import '../sentry_flutter.dart'; +import 'binding_utils.dart'; import 'event_processor/android_platform_exception_event_processor.dart'; import 'native_scope_observer.dart'; import 'sentry_native.dart'; @@ -44,8 +44,15 @@ mixin SentryFlutter { final native = SentryNative(); native.setNativeChannel(nativeChannel); - final wrapper = PlatformDispatcherWrapper(PlatformDispatcher.instance); - final isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); + final platformDispatcher = + BindingUtils.getWidgetsBindingInstance()?.platformDispatcher; + bool isOnErrorSupported; + if (platformDispatcher != null) { + final wrapper = PlatformDispatcherWrapper(platformDispatcher); + isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); + } else { + isOnErrorSupported = false; + } // first step is to install the native integration and set default values, // so we are able to capture future errors. From 412aa8367c59cb8d8972cbfcead5ed3093494b3f Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 3 Oct 2022 14:12:45 +0200 Subject: [PATCH 06/18] dont check if error is supported again --- flutter/lib/src/integrations/on_error_integration.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/flutter/lib/src/integrations/on_error_integration.dart b/flutter/lib/src/integrations/on_error_integration.dart index c6dad30761..440c197209 100644 --- a/flutter/lib/src/integrations/on_error_integration.dart +++ b/flutter/lib/src/integrations/on_error_integration.dart @@ -38,10 +38,6 @@ class OnErrorIntegration implements Integration { // WidgetsBinding works with WidgetsFlutterBinding and other custom bindings final wrapper = dispatchWrapper ?? PlatformDispatcherWrapper(binding.platformDispatcher); - - if (!wrapper.isOnErrorSupported(options)) { - return; - } _defaultOnError = wrapper.onError; _integrationOnError = (Object exception, StackTrace stackTrace) { From 7d6f830c2fc5b7cf917c8d306f17ef105ade4450 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 3 Oct 2022 14:22:51 +0200 Subject: [PATCH 07/18] mark callAppRunnerInRunZonedGuarded as internal --- dart/lib/src/sentry.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dart/lib/src/sentry.dart b/dart/lib/src/sentry.dart index 4af920d333..4d6f8feae9 100644 --- a/dart/lib/src/sentry.dart +++ b/dart/lib/src/sentry.dart @@ -36,7 +36,7 @@ class Sentry { static Future init( OptionsConfiguration optionsConfiguration, { AppRunner? appRunner, - bool callAppRunnerInRunZonedGuarded = true, + @internal bool callAppRunnerInRunZonedGuarded = true, @internal SentryOptions? options, }) async { final sentryOptions = options ?? SentryOptions(); From f3e8676846f1834afaa3f684ed603927076f3479 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 10 Oct 2022 10:53:06 +0200 Subject: [PATCH 08/18] use PlatformDispatcher.instance --- flutter/lib/src/sentry_flutter.dart | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index e5a5d47f3c..fe5e4bf066 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ui'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; @@ -44,15 +45,9 @@ mixin SentryFlutter { final native = SentryNative(); native.setNativeChannel(nativeChannel); - final platformDispatcher = - BindingUtils.getWidgetsBindingInstance()?.platformDispatcher; - bool isOnErrorSupported; - if (platformDispatcher != null) { - final wrapper = PlatformDispatcherWrapper(platformDispatcher); - isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); - } else { - isOnErrorSupported = false; - } + final platformDispatcher = PlatformDispatcher.instance; + final wrapper = PlatformDispatcherWrapper(platformDispatcher); + bool isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); // first step is to install the native integration and set default values, // so we are able to capture future errors. From 628880bbd6bb8a1c280a31d7ed45b0093c00fe0e Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 10 Oct 2022 11:12:05 +0200 Subject: [PATCH 09/18] move changelog entry to features --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 000e8f84d5..4e6c61d3b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,12 @@ ## Unreleased -### Fixes +### Features - Use PlatformDispatcher.onError in Flutter 3.3 ([#1039](https://github.com/getsentry/sentry-dart/pull/1039)) + +### Fixes + - Handle traces sampler exception ([#1040](https://github.com/getsentry/sentry-dart/pull/1040)) - tracePropagationTargets ignores invalid Regex ([#1043](https://github.com/getsentry/sentry-dart/pull/1043)) From 3e522494b0cde251ac0a018df4285a4f236af423 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 10:17:13 +0200 Subject: [PATCH 10/18] use type inference --- flutter/lib/src/sentry_flutter.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index fe5e4bf066..d6732693ba 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -47,7 +47,7 @@ mixin SentryFlutter { final platformDispatcher = PlatformDispatcher.instance; final wrapper = PlatformDispatcherWrapper(platformDispatcher); - bool isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); + final isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); // first step is to install the native integration and set default values, // so we are able to capture future errors. From 1c792b621d96c368a1302a4d27e446ccf7910bf0 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 10:17:34 +0200 Subject: [PATCH 11/18] ignore warning --- flutter/lib/src/sentry_flutter.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index d6732693ba..69bb59b1f2 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -65,6 +65,7 @@ mixin SentryFlutter { appRunner: appRunner, // ignore: invalid_use_of_internal_member options: flutterOptions, + // ignore: invalid_use_of_internal_member callAppRunnerInRunZonedGuarded: !isOnErrorSupported); } From 315be1485f79723681efa4c75b624833bca08411 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 10:36:15 +0200 Subject: [PATCH 12/18] remove unused import --- flutter/lib/src/sentry_flutter.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 69bb59b1f2..bd26264667 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -6,7 +6,6 @@ import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; import 'package:package_info_plus/package_info_plus.dart'; import '../sentry_flutter.dart'; -import 'binding_utils.dart'; import 'event_processor/android_platform_exception_event_processor.dart'; import 'native_scope_observer.dart'; import 'sentry_native.dart'; From 8189aafe929c0ff7737cefefa6e7b914e4296dd4 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 10:42:38 +0200 Subject: [PATCH 13/18] recreate mock.mocks.dart --- flutter/test/mocks.mocks.dart | 1141 +++++++++++++++++++++++---------- 1 file changed, 815 insertions(+), 326 deletions(-) diff --git a/flutter/test/mocks.mocks.dart b/flutter/test/mocks.mocks.dart index b6ab0745f0..24f6161823 100644 --- a/flutter/test/mocks.mocks.dart +++ b/flutter/test/mocks.mocks.dart @@ -1,10 +1,11 @@ -// Mocks generated by Mockito 5.2.0 from annotations +// Mocks generated by Mockito 5.3.2 from annotations // in sentry_flutter/example/windows/flutter/ephemeral/.plugin_symlinks/sentry_flutter/example/linux/flutter/ephemeral/.plugin_symlinks/sentry_flutter/example/ios/.symlinks/plugins/sentry_flutter/test/mocks.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i6; -import 'package:flutter/src/services/binding.dart' as _i5; +import 'package:flutter/src/services/binary_messenger.dart' as _i5; import 'package:flutter/src/services/message_codec.dart' as _i4; import 'package:flutter/src/services/platform_channel.dart' as _i9; import 'package:mockito/mockito.dart' as _i1; @@ -15,7 +16,6 @@ import 'package:sentry/src/sentry_tracer.dart' as _i8; import 'package:sentry_flutter/src/sentry_native.dart' as _i10; import 'package:sentry_flutter/src/sentry_native_channel.dart' as _i11; -// ignore_for_file: no_leading_underscores_for_library_prefixes import 'mocks.dart' as _i12; // ignore_for_file: type=lint @@ -30,25 +30,98 @@ import 'mocks.dart' as _i12; // ignore_for_file: subtype_of_sealed_class // ignore_for_file: invalid_use_of_internal_member -class _FakeSentrySpanContext_0 extends _i1.Fake - implements _i2.SentrySpanContext {} +class _FakeSentrySpanContext_0 extends _i1.SmartFake + implements _i2.SentrySpanContext { + _FakeSentrySpanContext_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeDateTime_1 extends _i1.Fake implements DateTime {} +class _FakeDateTime_1 extends _i1.SmartFake implements DateTime { + _FakeDateTime_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeISentrySpan_2 extends _i1.Fake implements _i2.ISentrySpan {} +class _FakeISentrySpan_2 extends _i1.SmartFake implements _i2.ISentrySpan { + _FakeISentrySpan_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeSentryTraceHeader_3 extends _i1.Fake - implements _i3.SentryTraceHeader {} +class _FakeSentryTraceHeader_3 extends _i1.SmartFake + implements _i3.SentryTraceHeader { + _FakeSentryTraceHeader_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeMethodCodec_4 extends _i1.Fake implements _i4.MethodCodec {} +class _FakeMethodCodec_4 extends _i1.SmartFake implements _i4.MethodCodec { + _FakeMethodCodec_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeBinaryMessenger_5 extends _i1.Fake implements _i5.BinaryMessenger {} +class _FakeBinaryMessenger_5 extends _i1.SmartFake + implements _i5.BinaryMessenger { + _FakeBinaryMessenger_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeSentryOptions_6 extends _i1.Fake implements _i2.SentryOptions {} +class _FakeSentryOptions_6 extends _i1.SmartFake implements _i2.SentryOptions { + _FakeSentryOptions_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeSentryId_7 extends _i1.Fake implements _i3.SentryId {} +class _FakeSentryId_7 extends _i1.SmartFake implements _i3.SentryId { + _FakeSentryId_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeHub_8 extends _i1.Fake implements _i2.Hub {} +class _FakeHub_8 extends _i1.SmartFake implements _i2.Hub { + _FakeHub_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} /// A class which mocks [Transport]. /// @@ -60,9 +133,13 @@ class MockTransport extends _i1.Mock implements _i2.Transport { @override _i6.Future<_i3.SentryId?> send(_i7.SentryEnvelope? envelope) => - (super.noSuchMethod(Invocation.method(#send, [envelope]), - returnValue: Future<_i3.SentryId?>.value()) - as _i6.Future<_i3.SentryId?>); + (super.noSuchMethod( + Invocation.method( + #send, + [envelope], + ), + returnValue: _i6.Future<_i3.SentryId?>.value(), + ) as _i6.Future<_i3.SentryId?>); } /// A class which mocks [SentryTracer]. @@ -74,107 +151,246 @@ class MockSentryTracer extends _i1.Mock implements _i8.SentryTracer { } @override - String get name => - (super.noSuchMethod(Invocation.getter(#name), returnValue: '') as String); + String get name => (super.noSuchMethod( + Invocation.getter(#name), + returnValue: '', + ) as String); @override - set name(String? _name) => super.noSuchMethod(Invocation.setter(#name, _name), - returnValueForMissingStub: null); + set name(String? _name) => super.noSuchMethod( + Invocation.setter( + #name, + _name, + ), + returnValueForMissingStub: null, + ); @override _i3.SentryTransactionNameSource get transactionNameSource => - (super.noSuchMethod(Invocation.getter(#transactionNameSource), - returnValue: _i3.SentryTransactionNameSource.custom) - as _i3.SentryTransactionNameSource); + (super.noSuchMethod( + Invocation.getter(#transactionNameSource), + returnValue: _i3.SentryTransactionNameSource.custom, + ) as _i3.SentryTransactionNameSource); @override set transactionNameSource( _i3.SentryTransactionNameSource? _transactionNameSource) => super.noSuchMethod( - Invocation.setter(#transactionNameSource, _transactionNameSource), - returnValueForMissingStub: null); - @override - _i2.SentrySpanContext get context => - (super.noSuchMethod(Invocation.getter(#context), - returnValue: _FakeSentrySpanContext_0()) as _i2.SentrySpanContext); - @override - DateTime get startTimestamp => - (super.noSuchMethod(Invocation.getter(#startTimestamp), - returnValue: _FakeDateTime_1()) as DateTime); - @override - Map get data => (super.noSuchMethod(Invocation.getter(#data), - returnValue: {}) as Map); - @override - bool get finished => - (super.noSuchMethod(Invocation.getter(#finished), returnValue: false) - as bool); - @override - List<_i3.SentrySpan> get children => - (super.noSuchMethod(Invocation.getter(#children), - returnValue: <_i3.SentrySpan>[]) as List<_i3.SentrySpan>); - @override - set throwable(dynamic throwable) => - super.noSuchMethod(Invocation.setter(#throwable, throwable), - returnValueForMissingStub: null); - @override - set status(_i3.SpanStatus? status) => - super.noSuchMethod(Invocation.setter(#status, status), - returnValueForMissingStub: null); - @override - Map get tags => (super.noSuchMethod(Invocation.getter(#tags), - returnValue: {}) as Map); - @override - Map get measurements => - (super.noSuchMethod(Invocation.getter(#measurements), - returnValue: {}) - as Map); - @override - _i6.Future finish({_i3.SpanStatus? status, DateTime? endTimestamp}) => + Invocation.setter( + #transactionNameSource, + _transactionNameSource, + ), + returnValueForMissingStub: null, + ); + @override + _i2.SentrySpanContext get context => (super.noSuchMethod( + Invocation.getter(#context), + returnValue: _FakeSentrySpanContext_0( + this, + Invocation.getter(#context), + ), + ) as _i2.SentrySpanContext); + @override + DateTime get startTimestamp => (super.noSuchMethod( + Invocation.getter(#startTimestamp), + returnValue: _FakeDateTime_1( + this, + Invocation.getter(#startTimestamp), + ), + ) as DateTime); + @override + Map get data => (super.noSuchMethod( + Invocation.getter(#data), + returnValue: {}, + ) as Map); + @override + bool get finished => (super.noSuchMethod( + Invocation.getter(#finished), + returnValue: false, + ) as bool); + @override + List<_i3.SentrySpan> get children => (super.noSuchMethod( + Invocation.getter(#children), + returnValue: <_i3.SentrySpan>[], + ) as List<_i3.SentrySpan>); + @override + set throwable(dynamic throwable) => super.noSuchMethod( + Invocation.setter( + #throwable, + throwable, + ), + returnValueForMissingStub: null, + ); + @override + set status(_i3.SpanStatus? status) => super.noSuchMethod( + Invocation.setter( + #status, + status, + ), + returnValueForMissingStub: null, + ); + @override + Map get tags => (super.noSuchMethod( + Invocation.getter(#tags), + returnValue: {}, + ) as Map); + @override + Map get measurements => (super.noSuchMethod( + Invocation.getter(#measurements), + returnValue: {}, + ) as Map); + @override + _i6.Future finish({ + _i3.SpanStatus? status, + DateTime? endTimestamp, + }) => (super.noSuchMethod( - Invocation.method( - #finish, [], {#status: status, #endTimestamp: endTimestamp}), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - void removeData(String? key) => - super.noSuchMethod(Invocation.method(#removeData, [key]), - returnValueForMissingStub: null); - @override - void removeTag(String? key) => - super.noSuchMethod(Invocation.method(#removeTag, [key]), - returnValueForMissingStub: null); - @override - void setData(String? key, dynamic value) => - super.noSuchMethod(Invocation.method(#setData, [key, value]), - returnValueForMissingStub: null); - @override - void setTag(String? key, String? value) => - super.noSuchMethod(Invocation.method(#setTag, [key, value]), - returnValueForMissingStub: null); - @override - _i2.ISentrySpan startChild(String? operation, - {String? description, DateTime? startTimestamp}) => + Invocation.method( + #finish, + [], + { + #status: status, + #endTimestamp: endTimestamp, + }, + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + void removeData(String? key) => super.noSuchMethod( + Invocation.method( + #removeData, + [key], + ), + returnValueForMissingStub: null, + ); + @override + void removeTag(String? key) => super.noSuchMethod( + Invocation.method( + #removeTag, + [key], + ), + returnValueForMissingStub: null, + ); + @override + void setData( + String? key, + dynamic value, + ) => + super.noSuchMethod( + Invocation.method( + #setData, + [ + key, + value, + ], + ), + returnValueForMissingStub: null, + ); + @override + void setTag( + String? key, + String? value, + ) => + super.noSuchMethod( + Invocation.method( + #setTag, + [ + key, + value, + ], + ), + returnValueForMissingStub: null, + ); + @override + _i2.ISentrySpan startChild( + String? operation, { + String? description, + DateTime? startTimestamp, + }) => (super.noSuchMethod( - Invocation.method(#startChild, [operation], - {#description: description, #startTimestamp: startTimestamp}), - returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan); + Invocation.method( + #startChild, + [operation], + { + #description: description, + #startTimestamp: startTimestamp, + }, + ), + returnValue: _FakeISentrySpan_2( + this, + Invocation.method( + #startChild, + [operation], + { + #description: description, + #startTimestamp: startTimestamp, + }, + ), + ), + ) as _i2.ISentrySpan); @override _i2.ISentrySpan startChildWithParentSpanId( - _i3.SpanId? parentSpanId, String? operation, - {String? description, DateTime? startTimestamp}) => + _i3.SpanId? parentSpanId, + String? operation, { + String? description, + DateTime? startTimestamp, + }) => (super.noSuchMethod( + Invocation.method( + #startChildWithParentSpanId, + [ + parentSpanId, + operation, + ], + { + #description: description, + #startTimestamp: startTimestamp, + }, + ), + returnValue: _FakeISentrySpan_2( + this, Invocation.method( - #startChildWithParentSpanId, - [parentSpanId, operation], - {#description: description, #startTimestamp: startTimestamp}), - returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan); - @override - _i3.SentryTraceHeader toSentryTrace() => - (super.noSuchMethod(Invocation.method(#toSentryTrace, []), - returnValue: _FakeSentryTraceHeader_3()) as _i3.SentryTraceHeader); - @override - void setMeasurement(String? name, num? value, - {_i2.SentryMeasurementUnit? unit}) => + #startChildWithParentSpanId, + [ + parentSpanId, + operation, + ], + { + #description: description, + #startTimestamp: startTimestamp, + }, + ), + ), + ) as _i2.ISentrySpan); + @override + _i3.SentryTraceHeader toSentryTrace() => (super.noSuchMethod( + Invocation.method( + #toSentryTrace, + [], + ), + returnValue: _FakeSentryTraceHeader_3( + this, + Invocation.method( + #toSentryTrace, + [], + ), + ), + ) as _i3.SentryTraceHeader); + @override + void setMeasurement( + String? name, + num? value, { + _i2.SentryMeasurementUnit? unit, + }) => super.noSuchMethod( - Invocation.method(#setMeasurement, [name, value], {#unit: unit}), - returnValueForMissingStub: null); + Invocation.method( + #setMeasurement, + [ + name, + value, + ], + {#unit: unit}, + ), + returnValueForMissingStub: null, + ); } /// A class which mocks [MethodChannel]. @@ -186,36 +402,81 @@ class MockMethodChannel extends _i1.Mock implements _i9.MethodChannel { } @override - String get name => - (super.noSuchMethod(Invocation.getter(#name), returnValue: '') as String); - @override - _i4.MethodCodec get codec => (super.noSuchMethod(Invocation.getter(#codec), - returnValue: _FakeMethodCodec_4()) as _i4.MethodCodec); - @override - _i5.BinaryMessenger get binaryMessenger => - (super.noSuchMethod(Invocation.getter(#binaryMessenger), - returnValue: _FakeBinaryMessenger_5()) as _i5.BinaryMessenger); - @override - _i6.Future invokeMethod(String? method, [dynamic arguments]) => - (super.noSuchMethod(Invocation.method(#invokeMethod, [method, arguments]), - returnValue: Future.value()) as _i6.Future); - @override - _i6.Future?> invokeListMethod(String? method, - [dynamic arguments]) => + String get name => (super.noSuchMethod( + Invocation.getter(#name), + returnValue: '', + ) as String); + @override + _i4.MethodCodec get codec => (super.noSuchMethod( + Invocation.getter(#codec), + returnValue: _FakeMethodCodec_4( + this, + Invocation.getter(#codec), + ), + ) as _i4.MethodCodec); + @override + _i5.BinaryMessenger get binaryMessenger => (super.noSuchMethod( + Invocation.getter(#binaryMessenger), + returnValue: _FakeBinaryMessenger_5( + this, + Invocation.getter(#binaryMessenger), + ), + ) as _i5.BinaryMessenger); + @override + _i6.Future invokeMethod( + String? method, [ + dynamic arguments, + ]) => (super.noSuchMethod( - Invocation.method(#invokeListMethod, [method, arguments]), - returnValue: Future?>.value()) as _i6.Future?>); - @override - _i6.Future?> invokeMapMethod(String? method, - [dynamic arguments]) => + Invocation.method( + #invokeMethod, + [ + method, + arguments, + ], + ), + returnValue: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future?> invokeListMethod( + String? method, [ + dynamic arguments, + ]) => (super.noSuchMethod( - Invocation.method(#invokeMapMethod, [method, arguments]), - returnValue: Future?>.value()) as _i6.Future?>); + Invocation.method( + #invokeListMethod, + [ + method, + arguments, + ], + ), + returnValue: _i6.Future?>.value(), + ) as _i6.Future?>); + @override + _i6.Future?> invokeMapMethod( + String? method, [ + dynamic arguments, + ]) => + (super.noSuchMethod( + Invocation.method( + #invokeMapMethod, + [ + method, + arguments, + ], + ), + returnValue: _i6.Future?>.value(), + ) as _i6.Future?>); @override void setMethodCallHandler( _i6.Future Function(_i4.MethodCall)? handler) => - super.noSuchMethod(Invocation.method(#setMethodCallHandler, [handler]), - returnValueForMissingStub: null); + super.noSuchMethod( + Invocation.method( + #setMethodCallHandler, + [handler], + ), + returnValueForMissingStub: null, + ); } /// A class which mocks [SentryNative]. @@ -227,82 +488,165 @@ class MockSentryNative extends _i1.Mock implements _i10.SentryNative { } @override - set appStartEnd(DateTime? _appStartEnd) => - super.noSuchMethod(Invocation.setter(#appStartEnd, _appStartEnd), - returnValueForMissingStub: null); + set appStartEnd(DateTime? _appStartEnd) => super.noSuchMethod( + Invocation.setter( + #appStartEnd, + _appStartEnd, + ), + returnValueForMissingStub: null, + ); @override - bool get didFetchAppStart => - (super.noSuchMethod(Invocation.getter(#didFetchAppStart), - returnValue: false) as bool); + bool get didFetchAppStart => (super.noSuchMethod( + Invocation.getter(#didFetchAppStart), + returnValue: false, + ) as bool); @override void setNativeChannel(_i11.SentryNativeChannel? nativeChannel) => - super.noSuchMethod(Invocation.method(#setNativeChannel, [nativeChannel]), - returnValueForMissingStub: null); - @override - _i6.Future<_i11.NativeAppStart?> fetchNativeAppStart() => - (super.noSuchMethod(Invocation.method(#fetchNativeAppStart, []), - returnValue: Future<_i11.NativeAppStart?>.value()) - as _i6.Future<_i11.NativeAppStart?>); - @override - _i6.Future beginNativeFramesCollection() => - (super.noSuchMethod(Invocation.method(#beginNativeFramesCollection, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + super.noSuchMethod( + Invocation.method( + #setNativeChannel, + [nativeChannel], + ), + returnValueForMissingStub: null, + ); + @override + _i6.Future<_i11.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod( + Invocation.method( + #fetchNativeAppStart, + [], + ), + returnValue: _i6.Future<_i11.NativeAppStart?>.value(), + ) as _i6.Future<_i11.NativeAppStart?>); + @override + _i6.Future beginNativeFramesCollection() => (super.noSuchMethod( + Invocation.method( + #beginNativeFramesCollection, + [], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); @override _i6.Future<_i11.NativeFrames?> endNativeFramesCollection( _i3.SentryId? traceId) => (super.noSuchMethod( - Invocation.method(#endNativeFramesCollection, [traceId]), - returnValue: Future<_i11.NativeFrames?>.value()) - as _i6.Future<_i11.NativeFrames?>); - @override - _i6.Future setContexts(String? key, dynamic value) => - (super.noSuchMethod(Invocation.method(#setContexts, [key, value]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future removeContexts(String? key) => - (super.noSuchMethod(Invocation.method(#removeContexts, [key]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setUser(_i3.SentryUser? sentryUser) => - (super.noSuchMethod(Invocation.method(#setUser, [sentryUser]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + Invocation.method( + #endNativeFramesCollection, + [traceId], + ), + returnValue: _i6.Future<_i11.NativeFrames?>.value(), + ) as _i6.Future<_i11.NativeFrames?>); + @override + _i6.Future setContexts( + String? key, + dynamic value, + ) => + (super.noSuchMethod( + Invocation.method( + #setContexts, + [ + key, + value, + ], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future removeContexts(String? key) => (super.noSuchMethod( + Invocation.method( + #removeContexts, + [key], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future setUser(_i3.SentryUser? sentryUser) => (super.noSuchMethod( + Invocation.method( + #setUser, + [sentryUser], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); @override _i6.Future addBreadcrumb(_i3.Breadcrumb? breadcrumb) => - (super.noSuchMethod(Invocation.method(#addBreadcrumb, [breadcrumb]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future clearBreadcrumbs() => - (super.noSuchMethod(Invocation.method(#clearBreadcrumbs, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setExtra(String? key, dynamic value) => - (super.noSuchMethod(Invocation.method(#setExtra, [key, value]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future removeExtra(String? key) => - (super.noSuchMethod(Invocation.method(#removeExtra, [key]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setTag(String? key, String? value) => - (super.noSuchMethod(Invocation.method(#setTag, [key, value]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future removeTag(String? key) => - (super.noSuchMethod(Invocation.method(#removeTag, [key]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - void reset() => super.noSuchMethod(Invocation.method(#reset, []), - returnValueForMissingStub: null); + (super.noSuchMethod( + Invocation.method( + #addBreadcrumb, + [breadcrumb], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future clearBreadcrumbs() => (super.noSuchMethod( + Invocation.method( + #clearBreadcrumbs, + [], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future setExtra( + String? key, + dynamic value, + ) => + (super.noSuchMethod( + Invocation.method( + #setExtra, + [ + key, + value, + ], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future removeExtra(String? key) => (super.noSuchMethod( + Invocation.method( + #removeExtra, + [key], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future setTag( + String? key, + String? value, + ) => + (super.noSuchMethod( + Invocation.method( + #setTag, + [ + key, + value, + ], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future removeTag(String? key) => (super.noSuchMethod( + Invocation.method( + #removeTag, + [key], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + void reset() => super.noSuchMethod( + Invocation.method( + #reset, + [], + ), + returnValueForMissingStub: null, + ); } /// A class which mocks [Hub]. @@ -314,159 +658,304 @@ class MockHub extends _i1.Mock implements _i2.Hub { } @override - _i2.SentryOptions get options => - (super.noSuchMethod(Invocation.getter(#options), - returnValue: _FakeSentryOptions_6()) as _i2.SentryOptions); - @override - bool get isEnabled => - (super.noSuchMethod(Invocation.getter(#isEnabled), returnValue: false) - as bool); - @override - _i3.SentryId get lastEventId => - (super.noSuchMethod(Invocation.getter(#lastEventId), - returnValue: _FakeSentryId_7()) as _i3.SentryId); - @override - _i6.Future<_i3.SentryId> captureEvent(_i3.SentryEvent? event, - {dynamic stackTrace, dynamic hint, _i2.ScopeCallback? withScope}) => + _i2.SentryOptions get options => (super.noSuchMethod( + Invocation.getter(#options), + returnValue: _FakeSentryOptions_6( + this, + Invocation.getter(#options), + ), + ) as _i2.SentryOptions); + @override + bool get isEnabled => (super.noSuchMethod( + Invocation.getter(#isEnabled), + returnValue: false, + ) as bool); + @override + _i3.SentryId get lastEventId => (super.noSuchMethod( + Invocation.getter(#lastEventId), + returnValue: _FakeSentryId_7( + this, + Invocation.getter(#lastEventId), + ), + ) as _i3.SentryId); + @override + _i6.Future<_i3.SentryId> captureEvent( + _i3.SentryEvent? event, { + dynamic stackTrace, + dynamic hint, + _i2.ScopeCallback? withScope, + }) => (super.noSuchMethod( - Invocation.method(#captureEvent, [ - event - ], { - #stackTrace: stackTrace, - #hint: hint, - #withScope: withScope - }), - returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) - as _i6.Future<_i3.SentryId>); - @override - _i6.Future<_i3.SentryId> captureException(dynamic throwable, - {dynamic stackTrace, dynamic hint, _i2.ScopeCallback? withScope}) => + Invocation.method( + #captureEvent, + [event], + { + #stackTrace: stackTrace, + #hint: hint, + #withScope: withScope, + }, + ), + returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( + this, + Invocation.method( + #captureEvent, + [event], + { + #stackTrace: stackTrace, + #hint: hint, + #withScope: withScope, + }, + ), + )), + ) as _i6.Future<_i3.SentryId>); + @override + _i6.Future<_i3.SentryId> captureException( + dynamic throwable, { + dynamic stackTrace, + dynamic hint, + _i2.ScopeCallback? withScope, + }) => (super.noSuchMethod( - Invocation.method(#captureException, [ - throwable - ], { - #stackTrace: stackTrace, - #hint: hint, - #withScope: withScope - }), - returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) - as _i6.Future<_i3.SentryId>); - @override - _i6.Future<_i3.SentryId> captureMessage(String? message, - {_i3.SentryLevel? level, - String? template, - List? params, - dynamic hint, - _i2.ScopeCallback? withScope}) => + Invocation.method( + #captureException, + [throwable], + { + #stackTrace: stackTrace, + #hint: hint, + #withScope: withScope, + }, + ), + returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( + this, + Invocation.method( + #captureException, + [throwable], + { + #stackTrace: stackTrace, + #hint: hint, + #withScope: withScope, + }, + ), + )), + ) as _i6.Future<_i3.SentryId>); + @override + _i6.Future<_i3.SentryId> captureMessage( + String? message, { + _i3.SentryLevel? level, + String? template, + List? params, + dynamic hint, + _i2.ScopeCallback? withScope, + }) => (super.noSuchMethod( - Invocation.method(#captureMessage, [ - message - ], { - #level: level, - #template: template, - #params: params, - #hint: hint, - #withScope: withScope - }), - returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) - as _i6.Future<_i3.SentryId>); + Invocation.method( + #captureMessage, + [message], + { + #level: level, + #template: template, + #params: params, + #hint: hint, + #withScope: withScope, + }, + ), + returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( + this, + Invocation.method( + #captureMessage, + [message], + { + #level: level, + #template: template, + #params: params, + #hint: hint, + #withScope: withScope, + }, + ), + )), + ) as _i6.Future<_i3.SentryId>); @override _i6.Future captureUserFeedback(_i2.SentryUserFeedback? userFeedback) => (super.noSuchMethod( - Invocation.method(#captureUserFeedback, [userFeedback]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future addBreadcrumb(_i3.Breadcrumb? crumb, {dynamic hint}) => + Invocation.method( + #captureUserFeedback, + [userFeedback], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future addBreadcrumb( + _i3.Breadcrumb? crumb, { + dynamic hint, + }) => (super.noSuchMethod( - Invocation.method(#addBreadcrumb, [crumb], {#hint: hint}), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - void bindClient(_i2.SentryClient? client) => - super.noSuchMethod(Invocation.method(#bindClient, [client]), - returnValueForMissingStub: null); - @override - _i2.Hub clone() => (super.noSuchMethod(Invocation.method(#clone, []), - returnValue: _FakeHub_8()) as _i2.Hub); - @override - _i6.Future close() => (super.noSuchMethod(Invocation.method(#close, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + Invocation.method( + #addBreadcrumb, + [crumb], + {#hint: hint}, + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + void bindClient(_i2.SentryClient? client) => super.noSuchMethod( + Invocation.method( + #bindClient, + [client], + ), + returnValueForMissingStub: null, + ); + @override + _i2.Hub clone() => (super.noSuchMethod( + Invocation.method( + #clone, + [], + ), + returnValue: _FakeHub_8( + this, + Invocation.method( + #clone, + [], + ), + ), + ) as _i2.Hub); + @override + _i6.Future close() => (super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); @override _i6.FutureOr configureScope(_i2.ScopeCallback? callback) => - (super.noSuchMethod(Invocation.method(#configureScope, [callback])) - as _i6.FutureOr); - @override - _i2.ISentrySpan startTransaction(String? name, String? operation, - {String? description, - DateTime? startTimestamp, - bool? bindToScope, - bool? waitForChildren, - Duration? autoFinishAfter, - bool? trimEnd, - _i2.OnTransactionFinish? onFinish, - Map? customSamplingContext}) => + (super.noSuchMethod(Invocation.method( + #configureScope, + [callback], + )) as _i6.FutureOr); + @override + _i2.ISentrySpan startTransaction( + String? name, + String? operation, { + String? description, + DateTime? startTimestamp, + bool? bindToScope, + bool? waitForChildren, + Duration? autoFinishAfter, + bool? trimEnd, + _i2.OnTransactionFinish? onFinish, + Map? customSamplingContext, + }) => (super.noSuchMethod( - Invocation.method(#startTransaction, [ - name, - operation - ], { - #description: description, - #startTimestamp: startTimestamp, - #bindToScope: bindToScope, - #waitForChildren: waitForChildren, - #autoFinishAfter: autoFinishAfter, - #trimEnd: trimEnd, - #onFinish: onFinish, - #customSamplingContext: customSamplingContext - }), - returnValue: _i12.startTransactionShim(name, operation, - description: description, - startTimestamp: startTimestamp, - bindToScope: bindToScope, - waitForChildren: waitForChildren, - autoFinishAfter: autoFinishAfter, - trimEnd: trimEnd, - onFinish: onFinish, - customSamplingContext: customSamplingContext)) - as _i2.ISentrySpan); + Invocation.method( + #startTransaction, + [ + name, + operation, + ], + { + #description: description, + #startTimestamp: startTimestamp, + #bindToScope: bindToScope, + #waitForChildren: waitForChildren, + #autoFinishAfter: autoFinishAfter, + #trimEnd: trimEnd, + #onFinish: onFinish, + #customSamplingContext: customSamplingContext, + }, + ), + returnValue: _i12.startTransactionShim( + name, + operation, + description: description, + startTimestamp: startTimestamp, + bindToScope: bindToScope, + waitForChildren: waitForChildren, + autoFinishAfter: autoFinishAfter, + trimEnd: trimEnd, + onFinish: onFinish, + customSamplingContext: customSamplingContext, + ), + ) as _i2.ISentrySpan); @override _i2.ISentrySpan startTransactionWithContext( - _i2.SentryTransactionContext? transactionContext, - {Map? customSamplingContext, - DateTime? startTimestamp, - bool? bindToScope, - bool? waitForChildren, - Duration? autoFinishAfter, - bool? trimEnd, - _i2.OnTransactionFinish? onFinish}) => + _i2.SentryTransactionContext? transactionContext, { + Map? customSamplingContext, + DateTime? startTimestamp, + bool? bindToScope, + bool? waitForChildren, + Duration? autoFinishAfter, + bool? trimEnd, + _i2.OnTransactionFinish? onFinish, + }) => (super.noSuchMethod( - Invocation.method(#startTransactionWithContext, [ - transactionContext - ], { + Invocation.method( + #startTransactionWithContext, + [transactionContext], + { #customSamplingContext: customSamplingContext, #startTimestamp: startTimestamp, #bindToScope: bindToScope, #waitForChildren: waitForChildren, #autoFinishAfter: autoFinishAfter, #trimEnd: trimEnd, - #onFinish: onFinish - }), - returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan); + #onFinish: onFinish, + }, + ), + returnValue: _FakeISentrySpan_2( + this, + Invocation.method( + #startTransactionWithContext, + [transactionContext], + { + #customSamplingContext: customSamplingContext, + #startTimestamp: startTimestamp, + #bindToScope: bindToScope, + #waitForChildren: waitForChildren, + #autoFinishAfter: autoFinishAfter, + #trimEnd: trimEnd, + #onFinish: onFinish, + }, + ), + ), + ) as _i2.ISentrySpan); @override _i6.Future<_i3.SentryId> captureTransaction( - _i3.SentryTransaction? transaction, - {_i2.SentryTraceContextHeader? traceContext}) => + _i3.SentryTransaction? transaction, { + _i2.SentryTraceContextHeader? traceContext, + }) => (super.noSuchMethod( - Invocation.method(#captureTransaction, [transaction], - {#traceContext: traceContext}), - returnValue: Future<_i3.SentryId>.value(_FakeSentryId_7())) - as _i6.Future<_i3.SentryId>); + Invocation.method( + #captureTransaction, + [transaction], + {#traceContext: traceContext}, + ), + returnValue: _i6.Future<_i3.SentryId>.value(_FakeSentryId_7( + this, + Invocation.method( + #captureTransaction, + [transaction], + {#traceContext: traceContext}, + ), + )), + ) as _i6.Future<_i3.SentryId>); @override void setSpanContext( - dynamic throwable, _i2.ISentrySpan? span, String? transaction) => + dynamic throwable, + _i2.ISentrySpan? span, + String? transaction, + ) => super.noSuchMethod( - Invocation.method(#setSpanContext, [throwable, span, transaction]), - returnValueForMissingStub: null); + Invocation.method( + #setSpanContext, + [ + throwable, + span, + transaction, + ], + ), + returnValueForMissingStub: null, + ); } From 609026b015c1f03006dad876384d96bf1ea36907 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 14:08:53 +0200 Subject: [PATCH 14/18] fix incorrect changelog --- CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9036b2a22..1c02dd2ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Use PlatformDispatcher.onError in Flutter 3.3 ([#1039](https://github.com/getsentry/sentry-dart/pull/1039)) + ## 6.12.1 ### Dependencies @@ -10,10 +16,6 @@ ## 6.12.0 -### Features - -- Use PlatformDispatcher.onError in Flutter 3.3 ([#1039](https://github.com/getsentry/sentry-dart/pull/1039)) - ### Fixes - Handle traces sampler exception ([#1040](https://github.com/getsentry/sentry-dart/pull/1040)) From a4d6e42e38857759d62d3cea09f9bd1fb7789899 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 16:40:43 +0200 Subject: [PATCH 15/18] add WidgetsFlutterBindingIntegration before OnErrorIntegration --- flutter/lib/src/sentry_flutter.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index bd26264667..612eda1fc5 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -102,14 +102,14 @@ mixin SentryFlutter { final platformChecker = options.platformChecker; final platform = platformChecker.platform; + // Will call WidgetsFlutterBinding.ensureInitialized() before all other integrations. + integrations.add(WidgetsFlutterBindingIntegration()); + // Use PlatformDispatcher.onError instead of zones. if (isOnErrorSupported) { integrations.add(OnErrorIntegration()); } - // Will call WidgetsFlutterBinding.ensureInitialized() before all other integrations. - integrations.add(WidgetsFlutterBindingIntegration()); - // Will catch any errors that may occur in the Flutter framework itself. integrations.add(FlutterErrorIntegration()); From 4ea91c6efb519e3f6bc801d05705e9f89b26e4f4 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 17:55:02 +0200 Subject: [PATCH 16/18] add newline --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e85ebd71ce..3450442042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - Use PlatformDispatcher.onError in Flutter 3.3 ([#1039](https://github.com/getsentry/sentry-dart/pull/1039)) + ### Fixes - Avoid dependency conflict with package_info_plus v2 ([#1068](https://github.com/getsentry/sentry-dart/pull/1068)) From 001e443ef221e15f74b346f034f94cbb03f48f23 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 11 Oct 2022 18:22:47 +0200 Subject: [PATCH 17/18] test that WidgetsFlutterBindingIntegration is before OnErrorIntegration --- flutter/test/sentry_flutter_test.dart | 49 +++++++++++++++++++++++++++ flutter/test/sentry_flutter_util.dart | 12 +++++++ 2 files changed, 61 insertions(+) diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index cd84e71a22..3905643048 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -10,6 +10,7 @@ import 'sentry_flutter_util.dart'; /// These are the integrations which should be added on every platform. /// They don't depend on the underlying platform. final platformAgnosticIntegrations = [ + WidgetsFlutterBindingIntegration, OnErrorIntegration, FlutterErrorIntegration, LoadReleaseIntegration, @@ -69,6 +70,14 @@ void main() { ], shouldNotHaveIntegrations: iOsAndMacOsIntegrations); + integrations + .indexWhere((element) => element is WidgetsFlutterBindingIntegration); + + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }, testOn: 'vm'); @@ -102,6 +111,11 @@ void main() { shouldNotHaveIntegrations: androidIntegrations, ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }, testOn: 'vm'); @@ -135,6 +149,11 @@ void main() { shouldNotHaveIntegrations: androidIntegrations, ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }, testOn: 'vm'); @@ -168,6 +187,11 @@ void main() { ], ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }, testOn: 'vm'); @@ -201,6 +225,11 @@ void main() { ], ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }, testOn: 'vm'); @@ -237,6 +266,11 @@ void main() { ], ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }); @@ -275,6 +309,11 @@ void main() { ], ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }); @@ -313,6 +352,11 @@ void main() { ], ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }); @@ -350,6 +394,11 @@ void main() { ], ); + testBefore( + integrations: integrations, + beforeIntegration: WidgetsFlutterBindingIntegration, + afterIntegration: OnErrorIntegration); + await Sentry.close(); }); }); diff --git a/flutter/test/sentry_flutter_util.dart b/flutter/test/sentry_flutter_util.dart index ac437eb5d6..154ea359af 100644 --- a/flutter/test/sentry_flutter_util.dart +++ b/flutter/test/sentry_flutter_util.dart @@ -34,3 +34,15 @@ void testConfiguration({ expect(integrations, isNot(contains(type))); } } + +void testBefore({ + required List integrations, + required Type beforeIntegration, + required Type afterIntegration, +}) { + final beforeIndex = integrations + .indexWhere((element) => element.runtimeType == beforeIntegration); + final afterIndex = integrations + .indexWhere((element) => element.runtimeType == afterIntegration); + expect(beforeIndex < afterIndex, true); +} From 485b071dea8cbb15fff33a5f9cda6f2cf56426ff Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 13 Oct 2022 10:34:52 +0200 Subject: [PATCH 18/18] fix --- dart/lib/src/sentry.dart | 7 +++++-- flutter/example/lib/main.dart | 14 -------------- flutter/example/pubspec.yaml | 2 +- flutter/lib/src/sentry_flutter.dart | 24 +++++++++++++++--------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/dart/lib/src/sentry.dart b/dart/lib/src/sentry.dart index 086e9aa033..8314a37d3d 100644 --- a/dart/lib/src/sentry.dart +++ b/dart/lib/src/sentry.dart @@ -97,8 +97,11 @@ class Sentry { } /// Initializes the SDK - static Future _init(SentryOptions options, AppRunner? appRunner, - bool callAppRunnerInRunZonedGuarded) async { + static Future _init( + SentryOptions options, + AppRunner? appRunner, + bool callAppRunnerInRunZonedGuarded, + ) async { if (isEnabled) { options.logger( SentryLevel.warning, diff --git a/flutter/example/lib/main.dart b/flutter/example/lib/main.dart index 7afdfe5f19..89b83d8bc2 100644 --- a/flutter/example/lib/main.dart +++ b/flutter/example/lib/main.dart @@ -187,20 +187,6 @@ class MainScaffold extends StatelessWidget { }, child: const Text('Capture from FlutterError.onError'), ), - ElevatedButton( - onPressed: () { - // Only usable on Flutter >= 3.3 - // and needs the following additional setup: - // options.addIntegration(OnErrorIntegration()); - (WidgetsBinding.instance.platformDispatcher as dynamic) - .onError - ?.call( - Exception('PlatformDispatcher.onError'), - StackTrace.current, - ); - }, - child: const Text('Capture from PlatformDispatcher.onError'), - ), ElevatedButton( onPressed: () => makeWebRequest(context), child: const Text('Dart: Web request'), diff --git a/flutter/example/pubspec.yaml b/flutter/example/pubspec.yaml index 9ea1146086..78d14ddb32 100644 --- a/flutter/example/pubspec.yaml +++ b/flutter/example/pubspec.yaml @@ -24,7 +24,7 @@ dependencies: dev_dependencies: pedantic: ^1.11.1 - sentry_dart_plugin: ^1.0.0-alpha.4 + sentry_dart_plugin: ^1.0.0-beta.1 dependency_overrides: sentry: diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 612eda1fc5..517ad8aa5f 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -51,21 +51,27 @@ mixin SentryFlutter { // first step is to install the native integration and set default values, // so we are able to capture future errors. final defaultIntegrations = _createDefaultIntegrations( - packageLoader, channel, flutterOptions, isOnErrorSupported); + packageLoader, + channel, + flutterOptions, + isOnErrorSupported, + ); for (final defaultIntegration in defaultIntegrations) { flutterOptions.addIntegration(defaultIntegration); } await _initDefaultValues(flutterOptions, channel); - await Sentry.init((options) async { - await optionsConfiguration(options as SentryFlutterOptions); - }, - appRunner: appRunner, - // ignore: invalid_use_of_internal_member - options: flutterOptions, - // ignore: invalid_use_of_internal_member - callAppRunnerInRunZonedGuarded: !isOnErrorSupported); + await Sentry.init( + (options) async { + await optionsConfiguration(options as SentryFlutterOptions); + }, + appRunner: appRunner, + // ignore: invalid_use_of_internal_member + options: flutterOptions, + // ignore: invalid_use_of_internal_member + callAppRunnerInRunZonedGuarded: !isOnErrorSupported, + ); } static Future _initDefaultValues(