From 21562c5f6156761d170bd39e03744de9d3f13cdf Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 5 Jun 2023 10:07:30 +0200 Subject: [PATCH] Enums use its name instead of non exhaustive switches (#1506) --- CHANGELOG.md | 4 ++++ dart/lib/src/protocol/sentry_device.dart | 15 +-------------- dart/lib/src/protocol/sentry_transaction.dart | 2 +- .../sentry_transaction_name_source.dart | 19 ------------------- .../flutter_enricher_event_processor.dart | 2 +- .../screenshot_event_processor.dart | 2 +- flutter/lib/src/renderer/renderer.dart | 13 ------------- flutter/lib/src/widgets_binding_observer.dart | 15 +-------------- flutter/test/mocks.dart | 14 -------------- 9 files changed, 9 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ea4060ebe..dac377d60c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Enums use its name instead of non exhaustive switches ([##1506](https://github.com/getsentry/sentry-dart/pull/#1506)) + ### Enhancements - Add http fields to `span.data` ([#1497](https://github.com/getsentry/sentry-dart/pull/1497)) diff --git a/dart/lib/src/protocol/sentry_device.dart b/dart/lib/src/protocol/sentry_device.dart index 188794010b..cad8c765f5 100644 --- a/dart/lib/src/protocol/sentry_device.dart +++ b/dart/lib/src/protocol/sentry_device.dart @@ -221,19 +221,6 @@ class SentryDevice { /// Produces a [Map] that can be serialized to JSON. Map toJson() { - String? orientation; - - switch (this.orientation) { - case SentryOrientation.portrait: - orientation = 'portait'; - break; - case SentryOrientation.landscape: - orientation = 'landscape'; - break; - case null: - orientation = null; - break; - } return { if (name != null) 'name': name, if (family != null) 'family': family, @@ -241,7 +228,7 @@ class SentryDevice { if (modelId != null) 'model_id': modelId, if (arch != null) 'arch': arch, if (batteryLevel != null) 'battery_level': batteryLevel, - if (orientation != null) 'orientation': orientation, + if (orientation != null) 'orientation': orientation!.name, if (manufacturer != null) 'manufacturer': manufacturer, if (brand != null) 'brand': brand, if (screenWidthPixels != null) 'screen_width_pixels': screenWidthPixels, diff --git a/dart/lib/src/protocol/sentry_transaction.dart b/dart/lib/src/protocol/sentry_transaction.dart index 28927009c9..44e6c4298f 100644 --- a/dart/lib/src/protocol/sentry_transaction.dart +++ b/dart/lib/src/protocol/sentry_transaction.dart @@ -69,7 +69,7 @@ class SentryTransaction extends SentryEvent { ); this.transactionInfo = transactionInfo ?? - SentryTransactionInfo(_tracer.transactionNameSource.toStringValue()); + SentryTransactionInfo(_tracer.transactionNameSource.name); } @override diff --git a/dart/lib/src/protocol/sentry_transaction_name_source.dart b/dart/lib/src/protocol/sentry_transaction_name_source.dart index dd701e7b59..278d1757a5 100644 --- a/dart/lib/src/protocol/sentry_transaction_name_source.dart +++ b/dart/lib/src/protocol/sentry_transaction_name_source.dart @@ -17,22 +17,3 @@ enum SentryTransactionNameSource { /// Name of a background task task, } - -extension SentryTransactionNameSourceExtension on SentryTransactionNameSource { - String toStringValue() { - switch (this) { - case SentryTransactionNameSource.custom: - return 'custom'; - case SentryTransactionNameSource.url: - return 'url'; - case SentryTransactionNameSource.route: - return 'route'; - case SentryTransactionNameSource.view: - return 'view'; - case SentryTransactionNameSource.component: - return 'component'; - case SentryTransactionNameSource.task: - return 'task'; - } - } -} diff --git a/flutter/lib/src/event_processor/flutter_enricher_event_processor.dart b/flutter/lib/src/event_processor/flutter_enricher_event_processor.dart index 571625f31c..f72eb2470b 100644 --- a/flutter/lib/src/event_processor/flutter_enricher_event_processor.dart +++ b/flutter/lib/src/event_processor/flutter_enricher_event_processor.dart @@ -143,7 +143,7 @@ class FlutterEnricherEventProcessor implements EventProcessor { // Also always fails in tests. // See https://github.com/flutter/flutter/issues/83919 // 'window_is_visible': _window.viewConfiguration.visible, - 'renderer': _options.rendererWrapper.getRendererAsString() + 'renderer': _options.rendererWrapper.getRenderer().name, }; } diff --git a/flutter/lib/src/event_processor/screenshot_event_processor.dart b/flutter/lib/src/event_processor/screenshot_event_processor.dart index 96ec4867b0..b60f4faefa 100644 --- a/flutter/lib/src/event_processor/screenshot_event_processor.dart +++ b/flutter/lib/src/event_processor/screenshot_event_processor.dart @@ -34,7 +34,7 @@ class ScreenshotEventProcessor implements EventProcessor { if (renderer != FlutterRenderer.skia && renderer != FlutterRenderer.canvasKit) { _options.logger(SentryLevel.debug, - 'Cannot take screenshot with ${_options.rendererWrapper.getRendererAsString()} renderer.'); + 'Cannot take screenshot with ${_options.rendererWrapper.getRenderer().name} renderer.'); return event; } diff --git a/flutter/lib/src/renderer/renderer.dart b/flutter/lib/src/renderer/renderer.dart index 5fdc238716..b1b9c2dd69 100644 --- a/flutter/lib/src/renderer/renderer.dart +++ b/flutter/lib/src/renderer/renderer.dart @@ -9,19 +9,6 @@ class RendererWrapper { FlutterRenderer getRenderer() { return implementation.getRenderer(); } - - String getRendererAsString() { - switch (getRenderer()) { - case FlutterRenderer.skia: - return 'Skia'; - case FlutterRenderer.canvasKit: - return 'CanvasKit'; - case FlutterRenderer.html: - return 'HTML'; - case FlutterRenderer.unknown: - return 'Unknown'; - } - } } enum FlutterRenderer { diff --git a/flutter/lib/src/widgets_binding_observer.dart b/flutter/lib/src/widgets_binding_observer.dart index 2778df3d5c..b199b7f8a5 100644 --- a/flutter/lib/src/widgets_binding_observer.dart +++ b/flutter/lib/src/widgets_binding_observer.dart @@ -71,7 +71,7 @@ class SentryWidgetsBindingObserver with WidgetsBindingObserver { category: 'app.lifecycle', type: 'navigation', data: { - 'state': _lifecycleToString(state), + 'state': state.name, }, // ignore: invalid_use_of_internal_member timestamp: _options.clock(), @@ -180,19 +180,6 @@ class SentryWidgetsBindingObserver with WidgetsBindingObserver { )); } - static String _lifecycleToString(AppLifecycleState state) { - switch (state) { - case AppLifecycleState.resumed: - return 'resumed'; - case AppLifecycleState.inactive: - return 'inactive'; - case AppLifecycleState.paused: - return 'paused'; - case AppLifecycleState.detached: - return 'detached'; - } - } - /* These are also methods of `WidgetsBindingObserver` but are currently not implemented because I'm not sure what to do with them. See the reasoning diff --git a/flutter/test/mocks.dart b/flutter/test/mocks.dart index db921b84fa..4a73e86b3b 100644 --- a/flutter/test/mocks.dart +++ b/flutter/test/mocks.dart @@ -354,20 +354,6 @@ class MockRendererWrapper implements RendererWrapper { FlutterRenderer getRenderer() { return _renderer; } - - @override - String getRendererAsString() { - switch (getRenderer()) { - case FlutterRenderer.skia: - return 'Skia'; - case FlutterRenderer.canvasKit: - return 'CanvasKit'; - case FlutterRenderer.html: - return 'HTML'; - case FlutterRenderer.unknown: - return 'Unknown'; - } - } } class TestBindingWrapper implements BindingWrapper {