Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing code_version in payload and don't set optional fields if … #5

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Flutter version ${{ matrix.flutter_version }}
strategy:
matrix:
flutter_version: ['2.0.5', '1.20.4']
flutter_version: ['2.0.5', '1.20.4', '2.2.3']

steps:
- uses: actions/checkout@v2
Expand Down
16 changes: 11 additions & 5 deletions rollbar_dart/lib/src/api/payload/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Data {
String platform;
String language;
String framework;
String codeVersion;
Level level;
int timestamp;
Body body;
Expand All @@ -24,17 +25,22 @@ class Data {
'client': client.toJson(),
'platform': platform,
'language': language,
'framework': framework,
'level': level.name,
'timestamp': timestamp,
'body': body.toJson(),
'custom': custom,
};

if (platformPayload != null) {
result['platform_payload'] = platformPayload;
}
addIfNotNull(result, 'framework', framework);
addIfNotNull(result, 'code_version', codeVersion);
addIfNotNull(result, 'custom', custom);
addIfNotNull(result, 'platform_payload', platformPayload);

return result;
}

void addIfNotNull(Map<String, dynamic> result, String name, dynamic value) {
if (value != null) {
result[name] = value;
}
}
}
4 changes: 2 additions & 2 deletions rollbar_dart/lib/src/core_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class CoreNotifier {
..language = 'dart'
..level = level
..platform = Platform.operatingSystem
..framework = _config.framework
..codeVersion = _config.codeVersion
..client = (Client()
..locale = Platform.localeName
..hostname = Platform.localHostname
Expand All @@ -51,8 +53,6 @@ class CoreNotifier {
..environment = _config.environment
..notifier = {'version': NOTIFIER_VERSION, 'name': NOTIFIER_NAME};

data.framework = _config.framework;

if (_transformer != null) {
data = await _transformer.transform(error, stackTrace, data);
}
Expand Down
28 changes: 27 additions & 1 deletion rollbar_dart/test/rollbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
// mock as the sender factory.
var config = (ConfigBuilder('BlaBlaAccessToken')
..environment = 'production'
..codeVersion = '1.0.0'
..codeVersion = '0.23.2'
..handleUncaughtErrors = false
..sender = (_) => sender)
.build();
Expand All @@ -36,6 +36,7 @@ void main() {
await rollbar.error(error, stackTrace);
var payload = verify(await sender.send(captureAny)).captured.single;

expect(payload['data']['code_version'], equals('0.23.2'));
expect(payload['data']['level'], equals('error'));

var trace = getPath(payload, ['data', 'body', 'trace']);
Expand All @@ -46,6 +47,31 @@ void main() {
}
});

test('If optional fields are not set they should not be added to the payload',
() async {
var config = (ConfigBuilder('BlaBlaAccessToken')
..environment = 'production'
..handleUncaughtErrors = false
..sender = (_) => sender)
.build();

rollbar = Rollbar(config);
await rollbar.ensureInitialized();

try {
failingFunction();
} catch (error, stackTrace) {
await rollbar.error(error, stackTrace);
var payload = verify(await sender.send(captureAny)).captured.single;

Map data = payload['data'];
expect(data, isNot(contains('code_version')));
expect(data, isNot(contains('framework')));
expect(data, isNot(contains('custom')));
expect(data, isNot(contains('platform_payload')));
}
});

test('If error trasformer is provided it should transform error', () async {
var config = (ConfigBuilder('token')
..environment = 'production'
Expand Down