Skip to content

Commit

Permalink
fix(oom): Report short version as app.version
Browse files Browse the repository at this point in the history
Add bundleVersion as separate field
  • Loading branch information
kattrali committed May 21, 2019
1 parent 57e67c9 commit 67055f2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
## 5.22.1 (2019-05-20)

* Fix handled stacktrace generation
* Report correct app version in out-of-memory reports. Previously the bundle
version was reported as the version number rather than the short version
string.
[#349](https://github.com/bugsnag/bugsnag-cocoa/pull/349)

[#348](https://github.com/bugsnag/bugsnag-cocoa/pull/348)

## 5.22.0 (2019-05-09)
Expand Down
10 changes: 8 additions & 2 deletions Source/BSGOutOfMemoryWatchdog.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ - (BOOL)computeDidOOMLastLaunchWithConfig:(BugsnagConfiguration *)config {
NSDictionary *lastBootInfo = [self readSentinelFile];
if (lastBootInfo != nil) {
self.lastBootCachedFileInfo = lastBootInfo;
NSString *lastBootBundleVersion =
[lastBootInfo valueForKeyPath:@"app.bundleVersion"];
NSString *lastBootAppVersion =
[lastBootInfo valueForKeyPath:@"app.version"];
NSString *lastBootOSVersion =
Expand All @@ -154,9 +156,12 @@ - (BOOL)computeDidOOMLastLaunchWithConfig:(BugsnagConfiguration *)config {
[[lastBootInfo valueForKeyPath:@"app.inForeground"] boolValue];
NSString *osVersion = [BSG_KSSystemInfo osBuildVersion];
NSDictionary *appInfo = [[NSBundle mainBundle] infoDictionary];
NSString *bundleVersion =
[appInfo valueForKey:@BSG_KSSystemField_BundleVersion];
NSString *appVersion =
[appInfo valueForKey:(__bridge NSString *)kCFBundleVersionKey];
[appInfo valueForKey:@BSG_KSSystemField_BundleShortVersion];
BOOL sameVersions = [lastBootOSVersion isEqualToString:osVersion] &&
[lastBootBundleVersion isEqualToString:bundleVersion] &&
[lastBootAppVersion isEqualToString:appVersion];
BOOL shouldReport = config.reportOOMs && (config.reportBackgroundOOMs || lastBootInForeground);
[self deleteSentinelFile];
Expand Down Expand Up @@ -214,7 +219,8 @@ - (NSMutableDictionary *)generateCacheInfoWithConfig:(BugsnagConfiguration *)con
app[@"id"] = systemInfo[@BSG_KSSystemField_BundleID] ?: @"";
app[@"name"] = systemInfo[@BSG_KSSystemField_BundleName] ?: @"";
app[@"releaseStage"] = config.releaseStage;
app[@"version"] = systemInfo[@BSG_KSSystemField_BundleVersion] ?: @"";
app[@"version"] = systemInfo[@BSG_KSSystemField_BundleShortVersion] ?: @"";
app[@"bundleVersion"] = systemInfo[@BSG_KSSystemField_BundleVersion] ?: @"";
app[@"inForeground"] = @YES;
#if TARGET_OS_TV
app[@"type"] = @"tvOS";
Expand Down
1 change: 1 addition & 0 deletions Tests/BugsnagCrashReportTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ - (void)testNoReportMetaData {
- (void)testAppVersion {
NSDictionary *dictionary = [self.report toJson];
XCTAssertEqualObjects(@"1.0", dictionary[@"app"][@"version"]);
XCTAssertEqualObjects(@"1", dictionary[@"app"][@"bundleVersion"]);
}

- (void)testAppVersionOverride {
Expand Down
4 changes: 4 additions & 0 deletions features/oom.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Feature: Reporting out of memory events
And the event "severity" equals "error"
And the event "severityReason.type" equals "outOfMemory"
And the event "app.releaseStage" equals "beta"
And the event "app.version" equals "1.0.3"
And the event "app.bundleVersion" equals "5"
And the event breadcrumbs contain "Crumb left before crash"

Scenario: The OS kills the application in the background
Expand All @@ -39,6 +41,8 @@ Feature: Reporting out of memory events
And the event "severity" equals "error"
And the event "severityReason.type" equals "outOfMemory"
And the event "app.releaseStage" equals "beta"
And the event "app.version" equals "1.0.3"
And the event "app.bundleVersion" equals "5"
And the event breadcrumbs contain "Crumb left before crash"

Scenario: The OS kills the application after a session is sent
Expand Down

0 comments on commit 67055f2

Please sign in to comment.