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

Guards for analytics crash #3810

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Conversation

bbirman
Copy link
Member

@bbirman bbirman commented Jan 23, 2025

Open to any ideas / changes to approach on this one

Backstory:
There's a crash with no repro steps that was originally reported on Sapp when [encryptedData writeToFile:filename options:NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication error:&error]; is called. @mbwimmer investigated and found that the fileName being nil could cause an exception but it was unclear how that scenario could happen (more discussion here). That fix went into Sapp's fork but now MP is also seeing the same issue (still no repro steps).

It looks like we do have a nullability conflict where SFSDKEventStoreManager's init method specifies a non-null storeDirectory but the method used to generate the directory that's eventually passed into that init method can return nil which would make the original fileName argument nil. Note: I still don't know what user scenario would cause that.

Two parts to the guards here:

  • Fail initialization of the analytics manager earlier if a nil directory is provided since events will never successfully write without it, avoids invalid init with SFSDKEventStoreManager
  • Add a guard around the method to catch the exception like @mbwimmer originally had in case there's another cause

Copy link

1 Warning
⚠️ Static Analysis found an issue with one or more files you modified. Please fix the issue(s).

Clang Static Analysis Issues

File Type Category Description Line Col
SFSDKSalesforceAnalyticsManager Nullability Memory error nil passed to a callee that requires a non-null 1st parameter 144 28
SFSDKSalesforceAnalyticsManager Nullability Memory error Null assigned to a pointer which is expected to have non-null value 313 38

Generated by 🚫 Danger

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 61.80%. Comparing base (40bcc28) to head (cf6cd3b).
Report is 11 commits behind head on dev.

Files with missing lines Patch % Lines
...ceAnalytics/Classes/Store/SFSDKEventStoreManager.m 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #3810      +/-   ##
==========================================
- Coverage   62.69%   61.80%   -0.89%     
==========================================
  Files         225      233       +8     
  Lines       21387    21751     +364     
==========================================
+ Hits        13408    13443      +35     
- Misses       7979     8308     +329     
Components Coverage Δ
Analytics 79.88% <85.71%> (-4.21%) ⬇️
Common 68.87% <ø> (ø)
Core 50.46% <100.00%> (-1.06%) ⬇️
SmartStore 73.70% <ø> (ø)
MobileSync 87.58% <ø> (ø)
Files with missing lines Coverage Δ
...lasses/Analytics/SFSDKSalesforceAnalyticsManager.m 50.77% <100.00%> (-5.59%) ⬇️
...ceAnalytics/Classes/Store/SFSDKEventStoreManager.m 72.10% <85.71%> (-16.39%) ⬇️

... and 9 files with indirect coverage changes

Copy link
Contributor

@Crebs Crebs left a comment

Choose a reason for hiding this comment

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

LGTM. I'm curious our the deprecated Method warning. Do we need to create another working to fix these warning I missed from last time?

@bbirman
Copy link
Member Author

bbirman commented Jan 23, 2025

LGTM. I'm curious our the deprecated Method warning. Do we need to create another working to fix these warning I missed from last time?

I don't remember seeing it then either :) I ran into it when I was doing something else recently so I have a local change I can send out soon

@bbirman bbirman merged commit 34ce7f8 into forcedotcom:dev Jan 23, 2025
8 of 9 checks passed
@bbirman bbirman deleted the analytics-crash branch January 23, 2025 23:30
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.

4 participants