Skip to content

Fixed ErrorUtils.purchasesError(withUntypedError:) on iOS 12#1982

Merged
NachoSoto merged 1 commit into
mainfrom
ios-12-test-failure
Oct 14, 2022
Merged

Fixed ErrorUtils.purchasesError(withUntypedError:) on iOS 12#1982
NachoSoto merged 1 commit into
mainfrom
ios-12-test-failure

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Oct 14, 2022

Copy link
Copy Markdown
Contributor

Fixes CSDK-491.
#1973 introduced an iOS-12 only regression:

image

For some reason the Swift runtime on iOS 12 fails to get the value from the Error existential, and gets a null pointer instead.

This workaround works, and it's equivalent on later iOS versions, just a bit redundant.

@NachoSoto NachoSoto force-pushed the ios-12-test-failure branch from 12e9a6d to 1e92bdf Compare October 14, 2022 18:23
@NachoSoto NachoSoto changed the title [WIP] Fixed iOS 12 tests Fixed ErrorUtils.purchasesError(withUntypedError:) on iOS 12 Oct 14, 2022
@NachoSoto NachoSoto requested a review from a team October 14, 2022 18:36
@NachoSoto NachoSoto marked this pull request as ready for review October 14, 2022 18:38
@NachoSoto NachoSoto force-pushed the ios-12-test-failure branch from 1e92bdf to 09cf3a2 Compare October 14, 2022 18:38
Comment thread Sources/Error Handling/ErrorUtils.swift Outdated
Comment on lines 297 to 298

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't have a radar or something we can link to here right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this'd break again in the future if we add another type of error but don't add it here before PurchasesErrorConvertible, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are there any cases that aren't covered by BackendError + NetworkError? if not maybe we can skip the PurchasesErrorConvertible line, so that if we add a new error type in the future it gets handled as default without crashing on iOS 12

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we don't have a radar or something we can link to here right?

Whatever it is, it's already fixed in future iOS versions, so they're not gonna bother. I also tried updating to the latest iOS 12.x to see if the fix is there, but 12.4 is the latest simulator we have available.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

are there any cases that aren't covered by BackendError + NetworkError?

In practice right now, no. But there are other types that conform to PurchasesErrorConvertible, just wouldn't be used in the code paths this is called now. But we can't guarantee that for the future unfortunately.

so that if we add a new error type in the future it gets handled as default without crashing on iOS 12

That would break the behavior in later iOS versions though. It's unfortunate we even need this in the first place, but we do because throws is not typed, and we're using it more and more with async throws instead of typed Results in completion-block APIs. Using this is what ensures that we don't end up throwing a StoreKitError instead of our own ErrorCode.

If we miss a type here, we would send "unknown error" instead, even though it's not really unknown.

But maybe that is the best approach for iOS 12. Let me change this to a runtime check so at least we avoid the crash! Stand by.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@NachoSoto NachoSoto force-pushed the ios-12-test-failure branch from 614f94d to db08779 Compare October 14, 2022 20:33
@NachoSoto NachoSoto merged commit c2a4df7 into main Oct 14, 2022
@NachoSoto NachoSoto deleted the ios-12-test-failure branch October 14, 2022 21:02
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.

2 participants