Skip to content

Commit

Permalink
Scope#setContexts pasing a List value would't not work (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Jul 27, 2022
1 parent 53b6921 commit 004b398
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

* `Scope#setContexts` pasing a List value would't not work ([#932](https://github.com/getsentry/sentry-dart/pull/932))

### Features

* Add integration for `PlatformDispatcher.onError` ([#915](https://github.com/getsentry/sentry-dart/pull/915))
Expand Down
10 changes: 9 additions & 1 deletion dart/lib/src/scope.dart
Expand Up @@ -118,7 +118,15 @@ class Scope {
Map<String, dynamic> get contexts => Map.unmodifiable(_contexts);

void _setContextsSync(String key, dynamic value) {
_contexts[key] = (value is num || value is bool || value is String)
// if it's a List, it should not be a List<SentryRuntime> because it can't
// be wrapped by the value object since it's a special property for having
// multiple runtimes and it has a dedicated property within the Contexts class.
_contexts[key] = (value is num ||
value is bool ||
value is String ||
(value is List &&
(value is! List<SentryRuntime> &&
key != SentryRuntime.listType)))
? {'value': value}
: value;
}
Expand Down
3 changes: 3 additions & 0 deletions dart/test/scope_test.dart
Expand Up @@ -488,6 +488,7 @@ void main() {
await scope.setContexts('theme', 'material');
await scope.setContexts('version', 9);
await scope.setContexts('location', {'city': 'London'});
await scope.setContexts('items', [1, 2, 3]);

final updatedEvent = await scope.applyToEvent(event);

Expand All @@ -505,6 +506,8 @@ void main() {
expect(updatedEvent?.contexts['theme']['value'], 'material');
expect(updatedEvent?.contexts['version']['value'], 9);
expect(updatedEvent?.contexts['location'], {'city': 'London'});
final items = updatedEvent?.contexts['items'];
expect(items['value'], [1, 2, 3]);
});

test('should apply the scope level', () async {
Expand Down

0 comments on commit 004b398

Please sign in to comment.