Skip to content

Commit

Permalink
add optional data to exception
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll committed Sep 9, 2024
1 parent fc52bcd commit d033b83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 6.1.3

- Require Dart 3.4.
- Added `isWasm` parameter to `Event.devtoolsEvent` constructor.
- Added `isWasm` parameter to the `Event.devtoolsEvent` constructor.
- Added an optional parameter `data` to the `Event.exception` constructor.

## 6.1.2

Expand Down
12 changes: 9 additions & 3 deletions pkgs/unified_analytics/lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,15 @@ final class Event {
/// exception that we want to log.
///
/// [exception] - string representation of the exception that occured.
Event.exception({required String exception})
: eventName = DashEvent.exception,
eventData = {'exception': exception};
/// [data] - optional structured data to include with the exception event.
Event.exception({
required String exception,
Map<String, Object?> data = const <String, Object?>{},
}) : eventName = DashEvent.exception,
eventData = {
'exception': exception,
...data,
};

/// Event that is emitted from the flutter tool when a build invocation
/// has been run by the user.
Expand Down
9 changes: 7 additions & 2 deletions pkgs/unified_analytics/test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,19 @@ void main() {
});

test('Event.exception constructed', () {
Event generateEvent() => Event.exception(exception: 'exception');
Event generateEvent() => Event.exception(
exception: 'exception',
data: {'foo': 'bar', 'baz': 1},
);

final constructedEvent = generateEvent();

expect(generateEvent, returnsNormally);
expect(constructedEvent.eventName, DashEvent.exception);
expect(constructedEvent.eventData['exception'], 'exception');
expect(constructedEvent.eventData.length, 1);
expect(constructedEvent.eventData['foo'], 'bar');
expect(constructedEvent.eventData['baz'], 1);
expect(constructedEvent.eventData.length, 3);
});

test('Event.timing constructed', () {
Expand Down

0 comments on commit d033b83

Please sign in to comment.