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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Crash when adding a crumb for a timezone change #3524

Merged
merged 3 commits into from Jan 3, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@

- TTFD waits for next drawn frame (#3505)
- Fix TTID/TTFD for app start transactions (#3512): TTID/TTFD spans and measurements for app start transaction now include the app start duration.
- Crash when adding a crumb for a timezone change (#3524)
- Fix a race condition in SentryTracer (#3523)
- Missing transactions when not calling `reportFullyDisplayed` (#3477)

Expand Down
14 changes: 9 additions & 5 deletions Sources/Sentry/SentrySystemEventBreadcrumbs.m
Expand Up @@ -240,11 +240,15 @@ - (void)timezoneEventTriggered:(NSNumber *)storedTimezoneOffset
NSInteger offset = SentryDependencyContainer.sharedInstance.dateProvider.timezoneOffset;

crumb.type = @"system";
crumb.data = @{
@"action" : @"TIMEZONE_CHANGE",
@"previous_seconds_from_gmt" : storedTimezoneOffset,
@"current_seconds_from_gmt" : @(offset)
};

NSMutableDictionary *dataDict =
[@{ @"action" : @"TIMEZONE_CHANGE", @"current_seconds_from_gmt" : @(offset) } mutableCopy];

if (storedTimezoneOffset != nil) {
dataDict[@"previous_seconds_from_gmt"] = storedTimezoneOffset;
}

crumb.data = dataDict;
[_delegate addBreadcrumb:crumb];

[self updateStoredTimezone];
Expand Down
@@ -1,3 +1,4 @@
import Nimble
@testable import Sentry
import SentryTestUtils
import XCTest
Expand Down Expand Up @@ -251,6 +252,20 @@ class SentrySystemEventBreadcrumbsTest: XCTestCase {
XCTAssertEqual(data["current_seconds_from_gmt"] as? Int64, 7_200)
}
}

func testTimezoneChangeNotificationBreadcrumb_NoStoredTimezoneOffset() {
sut = fixture.getSut(currentDevice: nil)

fixture.currentDateProvider.timezoneOffsetValue = 7_200
fixture.fileManager.deleteTimezoneOffset()

sut.timezoneEventTriggered()

assertBreadcrumbAction(action: "TIMEZONE_CHANGE") { data in
expect(data["previous_seconds_from_gmt"]) == nil
expect(data["current_seconds_from_gmt"] as? Int64) == 7_200
}
}

func testStopCallsSpecificRemoveObserverMethods() {
sut = fixture.getSut(currentDevice: nil)
Expand Down