Fixed ErrorUtils.purchasesError(withUntypedError:) on iOS 12#1982
Conversation
12e9a6d to
1e92bdf
Compare
ErrorUtils.purchasesError(withUntypedError:) on iOS 12
1e92bdf to
09cf3a2
Compare
There was a problem hiding this comment.
we don't have a radar or something we can link to here right?
There was a problem hiding this comment.
this'd break again in the future if we add another type of error but don't add it here before PurchasesErrorConvertible, right?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
614f94d to
db08779
Compare
Fixes CSDK-491.
#1973 introduced an iOS-12 only regression:
For some reason the Swift runtime on iOS 12 fails to get the value from the
Errorexistential, and gets a null pointer instead.This workaround works, and it's equivalent on later iOS versions, just a bit redundant.