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: Use new OneSignalClientError type for callbacks #1528

Merged
merged 6 commits into from
Dec 17, 2024

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Dec 16, 2024

Description

One Line Summary

Add a OneSignalClientError type in the HTTP client to pass to failure callbacks with more precise information.

Details

Motivation

  • This is to fix [Bug]: After latest fix I got another crash reports on Crashlytics 😔 #1526 and prevent future similar bugs.
  • The bugs are related to limitations of Objective-C to provide nullability and type safety
  • Using the generic NSError as the error object to callbacks leads to bugs when trying to read elements from the built-in userInfo dictionary, which can contain anything.
  • This reported crash happened as we read an element from that dictionary expecting the return value to be a dictionary. While true most of the time, it was sometimes an NSError instance instead, when JSON parsing of the HTTP response fails.
  • Now, calls to client to execute request will use this new OneSignalClientError object in the callback instead of NSError.

Scope

  • Direct calls to the client will receive OneSignalClientError, which wraps an underlying NSError instance.
  • Failure blocks further up the chain will still receive NSError, extracted from the underlying NSError.

Testing

Unit testing

Updated to build, no new ones added

Manual testing

iPhone 13 with iOS 18.1

  1. Reproduced reported crash exactly
  2. Fixed issue
  3. Forced different failure scenarios to test the changes are working

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
  • 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

@nan-li nan-li force-pushed the fix/client_error_callback branch from 82bab43 to 744f8fb Compare December 16, 2024 20:03
* Using the generic NSError as the error object to callbacks leads to bugs trying to read elements from userInfo which can contain anything.
* Calls to client to execute request will use this new OneSignalClientError object in the callback.
* Now that the OneSignalClientError type contains a nullable responseHeaders property, there is no need to default a null dictionary to be an empty dictionary
* This default was recently added to prevent a crash that is no longer an issue after these changes.
* Fetch IAM is the only place currently where additional information from a client failure callback is parsed. Update it to read the updated information.
@nan-li nan-li force-pushed the fix/client_error_callback branch from 744f8fb to 8186def Compare December 16, 2024 20:13
Base automatically changed from fix/iam_duration_since_last to main December 16, 2024 23:44
@nan-li nan-li merged commit 64d3eff into main Dec 17, 2024
1 of 2 checks passed
@nan-li nan-li deleted the fix/client_error_callback branch December 17, 2024 17:18
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.

[Bug]: After latest fix I got another crash reports on Crashlytics 😔
2 participants