Skip to content

fix(ios): guard against nil localizedDescription in didFailToLocateUserWithError#5872

Open
isaacrowntree wants to merge 1 commit intoreact-native-maps:masterfrom
isaacrowntree:fix/nil-guard-didFailToLocateUserWithError
Open

fix(ios): guard against nil localizedDescription in didFailToLocateUserWithError#5872
isaacrowntree wants to merge 1 commit intoreact-native-maps:masterfrom
isaacrowntree:fix/nil-guard-didFailToLocateUserWithError

Conversation

@isaacrowntree
Copy link

Summary

Fixes a crash in AIRMapManager.m where error.localizedDescription can be nil, causing an NSInvalidArgumentException when constructing the NSDictionary literal.

Crash:

NSInvalidArgumentException: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: 
attempt to insert nil object from objects[0]

Stack trace:

-[AIRMapManager mapView:didFailToLocateUserWithError:] (AIRMapManager.m:1244)
-[MKMapView locationManagerFailedToUpdateLocation:withError:]
-[MKLocationManager _reportLocationFailureWithError:]

Root cause

NSError.localizedDescription is documented to always return a non-nil string, but edge cases exist (custom error domains, specific iOS versions) where it can return nil. The Objective-C dictionary literal @{ @"message": nil } crashes immediately.

Fix

Add a nil-coalescing fallback: error.localizedDescription ?: @"Unknown error"

This is a one-line change with zero risk — it only affects the nil case which currently crashes.

Related

Test plan

  • Verified the fix compiles in Xcode
  • Confirmed the crash no longer occurs when localizedDescription is nil
  • No behavioral change for the normal (non-nil) case

…cateUserWithError

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant