Repository navigation
fix: guard MigrateFrom1To2 against DirectoryNotFoundException on init - #216
Merged
kaan-barmore-genc-mixpanel merged 1 commit intoAug 4, 2026
Conversation
The v1-to-v2 migration deleted legacy files (mp_state.json, mp_super_properties.json) via File.Delete inside finally blocks with no File.Exists guard and outside the protecting catch. File.Delete only tolerates a missing file when the parent directory exists, so when Application.persistentDataPath is empty or its directory is unavailable the delete throws DirectoryNotFoundException. Because it ran in finally, the surrounding catch did not swallow it, so the exception escaped Initialize(), left the SDK uninitialized, and made Start() take the fallback path and log 'Mixpanel fallback initialization failed'. Route both deletes through a best-effort helper that guards File.Exists and swallows exceptions, and skip migration when persistentDataPath is empty (without marking it done, so a later init can still run it). Fixes SDK-133
Confidence Score: 3/5The retry behavior should be fixed before merging because a transiently empty storage path can permanently skip migration of identity and consent state. The new early return preserves the migration flag but both callers subsequently set _fullyInitialized, preventing normal later initialization attempts from retrying the migration. Files Needing Attention: Mixpanel/Controller.cs
|
| Filename | Overview |
|---|---|
| Mixpanel/Controller.cs | Safely handles legacy-file cleanup, but an empty-path skip is not retried after initialization becomes complete. |
Reviews (1): Last reviewed commit: "fix: guard MigrateFrom1To2 against Direc..." | Re-trigger Greptile
jaredmixpanel
removed their request for review
July 28, 2026 21:43
tylerjroach
approved these changes
Jul 31, 2026
kaan-barmore-genc-mixpanel
deleted the
kaanbarmore-genc-sdk-133-unity-sdk-init-fails-with-directorynotfoundexception
branch
August 4, 2026 20:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes SDK-133. Customers hit a recurring init failure in the Unity SDK:
Mixpanel fallback initialization failed: System.IO.DirectoryNotFoundException ... /mp_state.json.Root cause
MigrateFrom1To2()inController.csdeleted legacy v1 files (mp_state.json,mp_super_properties.json) withFile.Deleteinsidefinallyblocks — noFile.Existsguard, and outside the protectingcatch.File.Deleteonly tolerates a missing file when the parent directory exists, so whenApplication.persistentDataPathis empty or its directory is unavailable, the delete throwsDirectoryNotFoundException. Running infinallymeant the surroundingcatchdid not swallow it, so the exception escapedInitialize(), left_fullyInitialized == false, andStart()took the fallback path and logged the customer-visible failure.persistentDataPathcan be empty when read off the Unity main thread, on tvOS, or with a malformed ProductName/CompanyName.Fix
DeleteLegacyFileBestEfforthelper that guardsFile.Existsand swallows exceptions — legacy cleanup is best-effort and must never abort init.persistentDataPathis empty, without marking migration done, so a later init can still run it.Testing
No automated coverage — the repo has a single EditMode test (
Identify_Test) and CI does not run it (Unity license required). Nothing exercises the migration path. Verified by inspection of the throw semantics.