@@ -555,8 +555,10 @@ - (void)captureReplayEvent:(SentryReplayEvent *)replayEvent
555555
556556 // Hybrid SDKs may override the sdk info for a replay Event,
557557 // the same SDK should be used for the envelope header.
558- SentrySdkInfo *sdkInfo = replayEvent.sdk ? [[SentrySdkInfo alloc ] initWithDict: replayEvent.sdk]
559- : [SentrySdkInfo global ];
558+ SentrySdkInfo *sdkInfo = replayEvent.sdk
559+ ? [[SentrySdkInfo alloc ]
560+ initWithDict: SENTRY_UNWRAP_NULLABLE_DICT (NSString *, id , replayEvent.sdk)]
561+ : [SentrySdkInfo global ];
560562 SentryEnvelopeHeader *envelopeHeader =
561563 [[SentryEnvelopeHeader alloc ] initWithId: replayEvent.eventId
562564 sdkInfo: sdkInfo
@@ -664,7 +666,7 @@ - (void)close
664666 SENTRY_LOG_DEBUG (@" Closed the Client." );
665667}
666668
667- - (SentryEvent *_Nullable)prepareEvent : (SentryEvent *)event
669+ - (SentryEvent *_Nullable)prepareEvent : (SentryEvent *_Nullable )event
668670 withScope : (SentryScope *)scope
669671 alwaysAttachStacktrace : (BOOL )alwaysAttachStacktrace
670672 isFatalEvent : (BOOL )isFatalEvent
@@ -713,7 +715,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
713715 event.dist = dist;
714716 }
715717
716- [self setSdk: event];
718+ [self setSdk: SENTRY_UNWRAP_NULLABLE (SentryEvent, event) ];
717719
718720 // We don't want to attach debug meta and stacktraces for transactions, replays or user
719721 // feedback.
@@ -759,25 +761,29 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
759761 // Crash events are from a previous run. Applying the current scope would potentially apply
760762 // current data.
761763 if (!isFatalEvent) {
762- event = [scope applyToEvent: event maxBreadcrumb: self .options.maxBreadcrumbs];
764+ // Unwrapping the event because we assume that the event will be returned
765+ event = SENTRY_UNWRAP_NULLABLE (
766+ SentryEvent, [scope applyToEvent: event maxBreadcrumb: self .options.maxBreadcrumbs]);
763767 }
764768
765769 if (!eventIsNotReplay) {
766770 event.breadcrumbs = nil ;
767771 }
768772
769- if ([self isWatchdogTermination: event isFatalEvent: isFatalEvent]) {
773+ if ([self isWatchdogTermination: SENTRY_UNWRAP_NULLABLE (SentryEvent, event)
774+ isFatalEvent: isFatalEvent]) {
770775 // Remove some mutable properties from the device/app contexts which are no longer
771776 // applicable
772- [self removeExtraDeviceContextFromEvent: event];
777+ [self removeExtraDeviceContextFromEvent: SENTRY_UNWRAP_NULLABLE (SentryEvent, event) ];
773778 } else if (!isFatalEvent) {
774779 // Store the current free memory battery level and more mutable properties,
775780 // at the time of this event, but not for crashes as the current data isn't guaranteed to be
776781 // the same as when the app crashed.
777- [self applyExtraDeviceContextToEvent: event];
778- [self applyCultureContextToEvent: event];
782+ [self applyExtraDeviceContextToEvent: SENTRY_UNWRAP_NULLABLE (SentryEvent, event) ];
783+ [self applyCultureContextToEvent: SENTRY_UNWRAP_NULLABLE (SentryEvent, event) ];
779784#if SENTRY_HAS_UIKIT
780- [self applyCurrentViewNamesToEventContext: event withScope: scope];
785+ [self applyCurrentViewNamesToEventContext: SENTRY_UNWRAP_NULLABLE (SentryEvent, event)
786+ withScope: scope];
781787#endif // SENTRY_HAS_UIKIT
782788 }
783789
@@ -788,7 +794,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
788794 }
789795
790796 // Need to do this after the scope is applied cause this sets the user if there is any
791- [self setUserIdIfNoUserSet: event];
797+ [self setUserIdIfNoUserSet: SENTRY_UNWRAP_NULLABLE (SentryEvent, event) ];
792798
793799 BOOL eventIsATransaction
794800 = event.type != nil && [event.type isEqualToString: SentryEnvelopeItemTypes.transaction];
@@ -822,7 +828,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
822828 }
823829
824830 if (eventIsNotUserFeedback && event != nil && nil != self.options .beforeSend ) {
825- event = self.options .beforeSend (event);
831+ event = self.options .beforeSend (SENTRY_UNWRAP_NULLABLE (SentryEvent, event) );
826832 if (event == nil ) {
827833 [self recordLost: eventIsNotATransaction reason: kSentryDiscardReasonBeforeSend ];
828834 if (eventIsATransaction) {
@@ -843,7 +849,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
843849 if (event != nil ) {
844850 // if the event is dropped by beforeSend we should not execute event processors as they
845851 // might trigger e.g. unnecessary replay capture
846- event = [self callEventProcessors: event];
852+ event = [self callEventProcessors: SENTRY_UNWRAP_NULLABLE (SentryEvent, event) ];
847853 if (event == nil ) {
848854 [self recordLost: eventIsNotATransaction reason: kSentryDiscardReasonEventProcessor ];
849855 if (eventIsATransaction) {
@@ -866,7 +872,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
866872 // We only want to call the callback once. It can occur that multiple crash events are
867873 // about to be sent.
868874 SentrySDKInternal.crashedLastRunCalled = YES ;
869- self.options .onCrashedLastRun (event);
875+ self.options .onCrashedLastRun (SENTRY_UNWRAP_NULLABLE (SentryEvent, event) );
870876 }
871877
872878 return event;
@@ -926,7 +932,7 @@ - (void)setSdk:(SentryEvent *)event
926932 event.sdk = [[[SentrySdkInfo alloc ] initWithOptions: self .options] serialize ];
927933}
928934
929- - (void )setUserInfo : (NSDictionary *)userInfo withEvent : (SentryEvent *)event
935+ - (void )setUserInfo : (NSDictionary *_Nullable )userInfo withEvent : (SentryEvent *_Nullable )event
930936{
931937 if (nil != event && nil != userInfo && userInfo.count > 0 ) {
932938 NSMutableDictionary *context;
@@ -989,14 +995,23 @@ - (void)applyExtraDeviceContextToEvent:(SentryEvent *)event
989995 [self modifyContext: event
990996 key: SENTRY_CONTEXT_DEVICE_KEY
991997 block: ^(NSMutableDictionary *device) {
992- [device addEntriesFromDictionary: extraContext[SENTRY_CONTEXT_DEVICE_KEY]];
998+ if (extraContext[SENTRY_CONTEXT_DEVICE_KEY] != nil &&
999+ [extraContext[SENTRY_CONTEXT_DEVICE_KEY]
1000+ isKindOfClass: NSDictionary .class]) {
1001+ [device addEntriesFromDictionary: extraContext[SENTRY_CONTEXT_DEVICE_KEY]
1002+ ?: @ {}];
1003+ }
9931004 }];
9941005
995- [self modifyContext: event
996- key: @" app"
997- block: ^(NSMutableDictionary *app) {
998- [app addEntriesFromDictionary: extraContext[@" app" ]];
999- }];
1006+ [self
1007+ modifyContext: event
1008+ key: SENTRY_CONTEXT_APP_KEY
1009+ block: ^(NSMutableDictionary *app) {
1010+ if (extraContext[SENTRY_CONTEXT_APP_KEY] != nil &&
1011+ [extraContext[SENTRY_CONTEXT_APP_KEY] isKindOfClass: NSDictionary .class]) {
1012+ [app addEntriesFromDictionary: extraContext[SENTRY_CONTEXT_APP_KEY] ?: @ {}];
1013+ }
1014+ }];
10001015}
10011016
10021017#if SENTRY_HAS_UIKIT
0 commit comments