LocalAuthentication error code not in enum (-1000)

we have the following code to perform biometric authentication


    class func canEvaluateDeviceOwnerAuthenticationWithBiometrics() -> (result: Bool, error: Error?) {
     
        var error: NSError?
        let result = LAContext().canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)
        return (result, error)
    }


after calling this method we translate it into an LAError and do a switch on the LAError.Code


let laError = LAError(_nsError: error as NSError)


sadly we had a crash on iphone 6, ios 12

apparently the code was -1000, which is not one of the enum options


Crashed: com.apple.main-thread

0 libswiftCore.dylib 0x102aefbbc specialized _assertionFailure(_:_:flags:) + 81808

1 libswiftCore.dylib 0x10294f1bc _diagnoseUnexpectedEnumCaseValue<A, B>(type:rawValue:) + 140412


how is this possible?

Replies

apparently the code was -1000, which is not one of the enum options

Indeed. I had a rummage around and it seems that this code basically translates to ‘internal error’. You should definitely file a bug about that, and if possible include a sysdiagnose log taken shortly after getting the error. Please post your bug number, just for the record.

If you’re not familiar with sysdiagnose logs, see the instructions on our Bug Reporting > Profiles and Logs page.

Taking a step back, having your code crash if it gets an unexpected error code is probably not a good idea. You should definitely change how you handle that error. It’s hard to make a specific recommendation without knowing more about your code, but the general way I deal with this is as follows:

let error = error as NSError
switch (error.domain, error.code) {
case (***, yyy): … handle specific case …
case (***, yyy): … handle specific case …
case (***, yyy): … handle specific case …
default: … handle everything else …
}

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"