Unexpected enum case 'MPIdentityErrorResponseCode'
Closed this issue · 3 comments
Hello team!
I recently met a weird crash that I cannot reproduce.
Below is the stacktrace, I would appreciate any information.
Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x125b8 _assertionFailure(_:_:flags:) + 228
1 libswiftCore.dylib 0x3b280 _diagnoseUnexpectedEnumCaseValue<A, B>(type:rawValue:) + 4692
2 KloveriOSApp 0x2158ac closure #1 in mParticleManager.logIn(user:) + 4301478060 (<compiler-generated>:4301478060)
3 KloveriOSApp 0x2159ec thunk for @escaping @callee_guaranteed (@guaranteed MPIdentityApiResult?, @guaranteed Error?) -> () + 4301478380 (<compiler-generated>:4301478380)
4 libdispatch.dylib 0x24b4 _dispatch_call_block_and_release + 32
5 libdispatch.dylib 0x3fdc _dispatch_client_callout + 20
6 libdispatch.dylib 0x127f4 _dispatch_main_queue_drain + 928
7 libdispatch.dylib 0x12444 _dispatch_main_queue_callback_4CF + 44
8 CoreFoundation 0x9a6d8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
9 CoreFoundation 0x7c03c __CFRunLoopRun + 2036
10 CoreFoundation 0x80ec0 CFRunLoopRunSpecific + 612
11 GraphicsServices 0x1368 GSEventRunModal + 164
12 UIKitCore 0x3a186c -[UIApplication _run] + 888
13 UIKitCore 0x3a14d0 UIApplicationMain + 340
14 KloveriOSApp 0xdc8c main + 34 (AppDelegate.swift:34)
15 ??? 0x1db436960 (Missing)
Key
crash_info_entry_0
Value
Fatal error: unexpected enum case 'MPIdentityErrorResponseCode(rawValue: 502)'
And Sometimes we get value like,
Fatal error: unexpected enum case 'MPIdentityErrorResponseCode(rawValue: 500)'
Could you check it, please?
Hi @VandanaPansuria, thanks for bringing this to our attention! So the core issue here seems to be the backend occasionally returning HTTP response codes that we don't expect (500 and 502). We have a definition in that enum for 504 (MPIdentityErrorResponseCodeTimeout) but not for the other 500 error codes.
This alone shouldn't be causing a crash however. In fact it's valid Swift code to do something like:
if let responseCode = MPIdentityErrorResponseCode(rawValue: 502) {
// Valid enum value
} else {
// Not a valid enum value
}
So just calling MPIdentityErrorResponseCode(rawValue: 502)
or MPIdentityErrorResponseCode(rawValue: 500)
should not cause your app to crash.
It's hard to know exactly what's going on without seeing your code, but I notice that the stack trace says <compiler-generated>
for the two stack frames that are from your app right before the crash, so it may be crashing in some autogenerated Swift/Obj-C bridge code or something...
Would you be ok with sharing the bit of code in your mParticleManager.logIn(user:)
function? Or at least just the bit relevant to the response handling?
In either cause, I've opened a ticket to track this internally as we should have enum values for these status codes if it's possible to have them returned, which would likely also solve your problem. But I'd love to know more about why this is actually crashing in the first place.
@einsteinx2 Thank you for your response. I think you are right with your solution, I have to add conditions for 502 and 500 errors.
And Yes, I can share a bit of code like,
MParticle.sharedInstance().upload()
guard let error = error else { return }
var params: [String: Any] = [
"user_id": user.uID,
"error": error.localizedDescription
]
guard
let resultCode = MPIdentityErrorResponseCode(rawValue: UInt((error as NSError).code))
else { return }
switch (resultCode) {
case .clientNoConnection, .clientSideTimeout:
//retry the IDSync request
case .requestInProgress, .retry, .timeout:
//inspect your implementation if this occurs frequency
//otherwise retry the IDSync request
case .unknown:
// inspect error.localizedDescription to determine why the request failed
// this typically means an implementation issue
case .unauthorized:
print("mparticle_login_error_unauthorized")
case .sslError:
print("mparticle_login_error_sslError")
case .optOut:
print("mparticle_login_error_optOut")
}
The missing enum values have been added in the latest release. Please update the mParticle SDK and let us know if you continue to see any issues with this.