For OSStatus, how to get a string explaining its meaning?

SecCopyErrorMessageString returns a string explaining the meaning of a security result code and its declaration is

func SecCopyErrorMessageString(
    _ status: OSStatus,
    _ reserved: UnsafeMutableRawPointer?
) -> CFString?

with typealias OSStatus = Int32

Having arbitrary OSStatus (for example for kAudioFormatUnsupportedDataFormatError it is 1718449215), is there something to get the description as string?

The idea would be analogous to:

let x: Int32 = 1718449215
if let errMsg = SecCopyErrorMessageString(x, nil) as? String{
    print(errMsg)
}

This is not a security result code, and the output is just OSStatus 1718449215, what I expect is a "string explaining the meaning".

Answered by DTS Engineer in 738431022

SecCopyErrorMessageString returns a string explaining the meaning of a security result code and its declaration is

Just FYI, you can access this from the command line:

% security error -25300    
Error: 0xFFFF9D2C -25300 The specified item could not be found in the keychain.

Having arbitrary OSStatus (for example for kAudioFormatUnsupportedDataFormatError it is 1718449215), is there something to get the description as string?

No. Your best option is to search the macOS SDK [1] looking for the code. That requires some tricks. For example, 1718449215 is 0x666d743f which encodes the ASCII characters fmt? and you need to search for that.

This assumes that you’re just trying to find out what the error means. If you’re looking for a user-visible, and hence localised, description of all OSStatus error codes, that doesn’t exist.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Due to the relatively timeline of OSStatus, macOS, and iOS, the macOS SDK is your best bet for finding OSStatus error codes.

Accepted Answer

SecCopyErrorMessageString returns a string explaining the meaning of a security result code and its declaration is

Just FYI, you can access this from the command line:

% security error -25300    
Error: 0xFFFF9D2C -25300 The specified item could not be found in the keychain.

Having arbitrary OSStatus (for example for kAudioFormatUnsupportedDataFormatError it is 1718449215), is there something to get the description as string?

No. Your best option is to search the macOS SDK [1] looking for the code. That requires some tricks. For example, 1718449215 is 0x666d743f which encodes the ASCII characters fmt? and you need to search for that.

This assumes that you’re just trying to find out what the error means. If you’re looking for a user-visible, and hence localised, description of all OSStatus error codes, that doesn’t exist.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Due to the relatively timeline of OSStatus, macOS, and iOS, the macOS SDK is your best bet for finding OSStatus error codes.

For OSStatus, how to get a string explaining its meaning?
 
 
Q