From 004b39832cf8854ac4e2bf3ea50c5c0dd458e7d8 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Wed, 27 Jul 2022 11:26:26 +0200 Subject: [PATCH] Scope#setContexts pasing a List value would't not work (#932) --- CHANGELOG.md | 4 ++++ dart/lib/src/scope.dart | 10 +++++++++- dart/test/scope_test.dart | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 785e82445..13bbde4c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/dart/lib/src/scope.dart b/dart/lib/src/scope.dart index 863847a4a..b62632f52 100644 --- a/dart/lib/src/scope.dart +++ b/dart/lib/src/scope.dart @@ -118,7 +118,15 @@ class Scope { Map 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 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 && + key != SentryRuntime.listType))) ? {'value': value} : value; } diff --git a/dart/test/scope_test.dart b/dart/test/scope_test.dart index e934325e3..af23745f0 100644 --- a/dart/test/scope_test.dart +++ b/dart/test/scope_test.dart @@ -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); @@ -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 {