Skip to content

Commit

Permalink
Enums use its name instead of non exhaustive switches (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Jun 5, 2023
1 parent 7e30648 commit 21562c5
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 77 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 1 addition & 14 deletions dart/lib/src/protocol/sentry_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,14 @@ class SentryDevice {

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
String? orientation;

switch (this.orientation) {
case SentryOrientation.portrait:
orientation = 'portait';
break;
case SentryOrientation.landscape:
orientation = 'landscape';
break;
case null:
orientation = null;
break;
}
return <String, dynamic>{
if (name != null) 'name': name,
if (family != null) 'family': family,
if (model != null) 'model': model,
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,
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/protocol/sentry_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SentryTransaction extends SentryEvent {
);

this.transactionInfo = transactionInfo ??
SentryTransactionInfo(_tracer.transactionNameSource.toStringValue());
SentryTransactionInfo(_tracer.transactionNameSource.name);
}

@override
Expand Down
19 changes: 0 additions & 19 deletions dart/lib/src/protocol/sentry_transaction_name_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 0 additions & 13 deletions flutter/lib/src/renderer/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 1 addition & 14 deletions flutter/lib/src/widgets_binding_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SentryWidgetsBindingObserver with WidgetsBindingObserver {
category: 'app.lifecycle',
type: 'navigation',
data: <String, String>{
'state': _lifecycleToString(state),
'state': state.name,
},
// ignore: invalid_use_of_internal_member
timestamp: _options.clock(),
Expand Down Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions flutter/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 21562c5

Please sign in to comment.