AudioHardwareError: No Access to Int32 error constants

I am unable to access the Int32 error from the errors that CoreAudio throws in Swift type AudioHardwareError. This is critical. There is no way to access the errors or even create an AudioHardwareError to test for errors.

do {
    _ = try AudioHardwareDevice(id: 0).streams // will throw
} catch {
    if let error = error as? AudioHardwareError { // cast to AudioHardwareError
        
        print(error) // prints error code but not the errorDescription
    }
}

How can get reliably get the error.Int32? Or create a AudioHardwareError with an error constant? There is no way for me to handle these error with code or run tests without knowing what the error is.

On top of that, by default the error localizedDescription does not contain the errorDescription unless I extend AudioHardwareError with CustomStringConvertible.

extension AudioHardwareError: @retroactive CustomStringConvertible {
    public var description: String {
        return self.localizedDescription
    }
}
Answered by DTS Engineer in 818685022

Hello @existentialaudio,

Ok, I see the issue now. There is no way to access the underlying OSStatus value of AudioHardwareError, please file an enhancement request using Feedback Assistant if you have not already done so.

-Greg

Hello @existentialaudio,

AudioHardwareError has an errorDescription property, is that what you are seeking?

if let error = error as? AudioHardwareError {
    print(error.errorDescription ?? "no description.")
}

Best regards,

Greg

Hello @existentialaudio,

Ok, I see the issue now. There is no way to access the underlying OSStatus value of AudioHardwareError, please file an enhancement request using Feedback Assistant if you have not already done so.

-Greg

AudioHardwareError: No Access to Int32 error constants
 
 
Q