Skip to content

Conversation

@nan-li
Copy link
Contributor

@nan-li nan-li commented Oct 14, 2025

Description

One Line Summary

To log an error, use its description rather than localizedDescription, which can cause exceptions.

Details

  • It seems that when creating a new string with NSString stringWithFormat, copying the localizedDescription can raise an NSInvalidArgumentException. Not reproducible, but reported by users. Those reports were from a non-Americas locale.
  • This usage of description rather than localizedDescription matches other calls to the client where we log the error returned. This is likely why we did not received reports of crashes in those calls.
  • In addition, localizedDescription was never used on player model, it logged the error directly which internally calls the error's description.

Example stacktrace:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x... __exceptionPreprocess
1  libobjc.A.dylib                0x... objc_exception_throw
2  CoreFoundation                 0x... +[NSObject(NSObject) _copyDescription]
3  CoreFoundation                 0x... ___forwarding___
4  CoreFoundation                 0x... _CF_forwarding_prep_0
5  OneSignalInAppMessages         0x... __77-[OSMessagingController attemptFetchWithRetries:rywData:attempts:retryLimit:]_block_invoke.90 + 320 (OSMessagingController.m:320)
6  OneSignalCore                  0x... -[OneSignalClient handleJSONNSURLResponse:data:error:isAsync:withRequest:onSuccess:onFailure:] + 214 (OneSignalClient.m:214)
7  OneSignalCore                  0x... __54-[OneSignalClient executeRequest:onSuccess:onFailure:]_block_invoke + 110 (OneSignalClient.m:110)

Motivation

Fix reported crash

Scope

  • Logging only

Testing

Unit testing

None added

Manual testing

None, unable to reproduce by attempting:

  • GET https://onesignal.com/foo (returns invalid JSON, and 404 response) and GET https://onesignal.com/ (returns invalid JSON and 200 response)
  • Change my phone’s region and language to various locales and make the above GETs
  • No crash experienced. The localizedDescription always printed “The data couldn’t be read because it isn’t in the correct format.”

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible - LOCALLY
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

* It seems that when creating a new string with stringWithFormat, copying the `localizedDescription` can raise an `NSInvalidArgumentException`. Not reproducible, but reported by users.
* This matches other calls to the client where we log the error returned.

Example stacktrace:
Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x... __exceptionPreprocess
1  libobjc.A.dylib                0x... objc_exception_throw
2  CoreFoundation                 0x... +[NSObject(NSObject) _copyDescription]
3  CoreFoundation                 0x... ___forwarding___
4  CoreFoundation                 0x... _CF_forwarding_prep_0
5  OneSignalInAppMessages         0x... __77-[OSMessagingController attemptFetchWithRetries:rywData:attempts:retryLimit:]_block_invoke.90 + 320 (OSMessagingController.m:320)
6  OneSignalCore                  0x... -[OneSignalClient handleJSONNSURLResponse:data:error:isAsync:withRequest:onSuccess:onFailure:] + 214 (OneSignalClient.m:214)
7  OneSignalCore                  0x... __54-[OneSignalClient executeRequest:onSuccess:onFailure:]_block_invoke + 110 (OneSignalClient.m:110)
@nan-li nan-li requested review from a team, jinliu9508 and jkasten2 October 20, 2025 17:04
@nan-li nan-li merged commit f6027db into main Oct 20, 2025
3 of 4 checks passed
@nan-li nan-li deleted the fix/nserror_localized_description_errors branch October 20, 2025 20:44
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