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: app crash on identify method #458

Merged
merged 3 commits into from Jan 3, 2024

Conversation

ami-aman
Copy link
Contributor

@ami-aman ami-aman commented Jan 2, 2024

This PR fixes the following scenario:
Sample app was crashing in a scenario where the user sends nil value for body in identify method. The specific use case is when a user clicks Generate Random Login and attempts to login without a body.

Complete each step to get your pull request merged in. Learn more about the workflow this project uses.

  • Assign members of your team to review the pull request.
  • Wait for pull request status checks to complete. If there are problems, fix them until you see that all status checks are passing.
  • Wait until the pull request has been reviewed and approved by a teammate
  • After code reviews are approved and you determine this PR is ready to merge, select Squash and Merge button on this screen, leave the title and description to the default values, then merge the PR.

@ami-aman ami-aman requested a review from a team January 2, 2024 12:10
Copy link

github-actions bot commented Jan 2, 2024

Sample app builds 📱

Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.


  • CocoaPods-FCM: Build failed. See CI job logs to determine the issue and try re-building.
  • APN-UIKit: cdp-fix-identify-crash (1704197503)

// (refer https://github.com/customerio/customerio-ios/blob/94cbf686c3c2a405534cfe908f7166558a3e0b5d/Sources/Tracking/CustomerIO.swift#L71-L75)
if let optionalValue = body as? Any?, optionalValue == nil {
implementation?.identify(identifier: identifier, body: EmptyRequestBody())
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal preference opinion only,

if and else, over early return.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference again but I would prefer guard which I think is more common in Swift and our codebase 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant this, think this would have worked.

if let optionalValue = body as? Any?, optionalValue == nil {
            implementation?.identify(identifier: identifier, body: EmptyRequestBody())
        } else {
            implementation?.identify(identifier: identifier, body: body)
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this would have worked. I understand it is a personal preference but does it affect the business logic and working of the fix ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't and hence, didn't say so either. 😄

I was just responding to this reply, that the personal preference I was mentioning was utilizing the same logic for comparison. We choose to go with it or not thats another thing.

I do agree that there could be personal preferences but swift doesn't allow the conversion and hence the alternative approach has been followed here for comparison of a non-nil property with nil.

// (refer https://github.com/customerio/customerio-ios/blob/94cbf686c3c2a405534cfe908f7166558a3e0b5d/Sources/Tracking/CustomerIO.swift#L71-L75)
if let optionalValue = body as? Any?, optionalValue == nil {
implementation?.identify(identifier: identifier, body: EmptyRequestBody())
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference again but I would prefer guard which I think is more common in Swift and our codebase 😄

@ami-aman
Copy link
Contributor Author

ami-aman commented Jan 3, 2024

@mrehan27 @Shahroz16 directly converting a non-optional property to optional isn't possible in Swift. This is one of the ways we can indirectly attain what's said above. I do agree that there could be personal preferences but swift doesn't allow the conversion and hence the alternative approach has been followed here for comparison of a non-nil property with nil.

@ami-aman ami-aman merged commit 13e9862 into main-replica-for-cdp Jan 3, 2024
5 of 7 checks passed
@ami-aman ami-aman deleted the cdp-fix-identify-crash branch January 3, 2024 14:37
@levibostian
Copy link
Member

I would like to request automated tests for this fix. Was there a reason for not adding them in the PR I am unaware of?

@ami-aman
Copy link
Contributor Author

ami-aman commented Jan 4, 2024

I would like to request automated tests for this fix. Was there a reason for not adding them in the PR I am unaware of?

We are updating the test cases separately as a part of clean up.

github-actions bot pushed a commit that referenced this pull request Mar 20, 2024
## [3.0.0](2.12.5...3.0.0) (2024-03-20)

### ⚠ BREAKING CHANGES

* iOS as a source for Data Pipelines (#659)

### Features

* iOS as a source for Data Pipelines ([#659](#659)) ([0a68373](0a68373))
* migration module to cater to all migration tasks  ([#530](#530)) ([2feb1d4](2feb1d4))

### Bug Fixes

* add attributes to properties  ([#649](#649)) ([4b02e92](4b02e92))
* all sdk modules can only be initialized once ([ae46c7f](ae46c7f))
* app crash on identify method ([#458](#458)) ([13e9862](13e9862))
* compilation for test ([f14b773](f14b773))
* compilation issue ([420a61e](420a61e))
* eventbus handler ref ([#469](#469)) ([8c8ef91](8c8ef91))
* journey id in migration payload ([#653](#653)) ([3b649c9](3b649c9))
* prevent duplicate automatic screenview events from being tracked ([fea9ec5](fea9ec5))
* pushEventHandler test ([dc80fc2](dc80fc2))
* remove occurrence of autoTrackDeviceAttributes from all push modules ([#505](#505)) ([8dc6507](8dc6507))
* removed last_used from properties  ([#477](#477)) ([b0b9631](b0b9631))
* sample app issues ([#551](#551)) ([05544b3](05544b3))
* use git commit instead of git branch for segment dependency ([d245015](d245015))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants