From 9ed67dcf9c5465d43dad6fd0ed9145163101de59 Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Wed, 29 Sep 2021 10:44:04 +0100 Subject: [PATCH 1/2] Fix missing user info from config in crashing errors PLAT-7374 --- Bugsnag/Client/BugsnagClient.m | 13 ++++++++----- .../shared/scenarios/BareboneTestScenarios.swift | 7 +++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Bugsnag/Client/BugsnagClient.m b/Bugsnag/Client/BugsnagClient.m index 9e101091b..531f659cb 100644 --- a/Bugsnag/Client/BugsnagClient.m +++ b/Bugsnag/Client/BugsnagClient.m @@ -204,10 +204,17 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)configuration { if ((self = [super init])) { // Take a shallow copy of the configuration _configuration = [configuration copy]; + + if (!_configuration.user.id) { // populate with an autogenerated ID if no value set + [_configuration setUser:[BSG_KSSystemInfo deviceAndAppHash] withEmail:_configuration.user.email andName:_configuration.user.name]; + } + _state = [[BugsnagMetadata alloc] initWithDictionary:@{ BSGKeyApp: @{BSGKeyIsLaunching: @YES}, - BSGKeyClient: BSGDictionaryWithKeyAndObject(BSGKeyContext, _configuration.context) + BSGKeyClient: BSGDictionaryWithKeyAndObject(BSGKeyContext, _configuration.context), + BSGKeyUser: [configuration.user toJson] }]; + _notifier = configuration.notifier ?: [[BugsnagNotifier alloc] init]; self.systemState = [[BugsnagSystemState alloc] initWithConfiguration:configuration]; @@ -266,10 +273,6 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)configuration { self.pluginClient = [[BugsnagPluginClient alloc] initWithPlugins:self.configuration.plugins client:self]; - if (self.user.id == nil) { // populate with an autogenerated ID if no value set - [self setUser:[BSG_KSSystemInfo deviceAndAppHash] withEmail:configuration.user.email andName:configuration.user.name]; - } - BSGInternalErrorReporter.sharedInstance = [[BSGInternalErrorReporter alloc] initWithDataSource:self]; } return self; diff --git a/features/fixtures/shared/scenarios/BareboneTestScenarios.swift b/features/fixtures/shared/scenarios/BareboneTestScenarios.swift index e9e28c590..7f6c6b1e0 100644 --- a/features/fixtures/shared/scenarios/BareboneTestScenarios.swift +++ b/features/fixtures/shared/scenarios/BareboneTestScenarios.swift @@ -111,17 +111,16 @@ class BareboneTestUnhandledErrorScenario: Scenario { } } else { // The version of the app at crash time. + config.addMetadata(["group": "users"], section: "user") config.appVersion = "12.3" config.bundleVersion = "12301" + config.context = "Something" + config.setUser("barfoo", withEmail: "barfoo@example.com", andName: "Bar Foo") } super.startBugsnag() } override func run() { - Bugsnag.setContext("Something") - Bugsnag.setUser("barfoo", withEmail: "barfoo@example.com", andName: "Bar Foo") - Bugsnag.addMetadata(["group": "users"], section: "user") - // Triggers "Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: ..." print(payload.name) } From 330ccdef2a80a6326ded51661776035814c1ae7f Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Wed, 20 Oct 2021 15:03:11 +0100 Subject: [PATCH 2/2] Update crash-time session info when resumed --- Bugsnag/BugsnagSessionTracker.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Bugsnag/BugsnagSessionTracker.m b/Bugsnag/BugsnagSessionTracker.m index ed89859a6..07389b4fb 100644 --- a/Bugsnag/BugsnagSessionTracker.m +++ b/Bugsnag/BugsnagSessionTracker.m @@ -147,6 +147,9 @@ - (BOOL)resumeSession { } else { BOOL stopped = session.isStopped; [session resume]; + if (self.callback) { + self.callback(session); + } [self postUpdateNotice]; return stopped; }