Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert an iPhone OSStatus code to something useful?

I am getting more than a little sick of this iPhone SDK and its documentation...

I am calling AudioConverterNew

in the documentation under Returns: it says "returns a status code" ... really...

so far, through playing around with the parameters I have only been able to get two different errors neither of which are listed at the bottom of the Audio Converter reference.

they are 'mrep' and '?tmf' (casting the OSStatus to a char array) but the specific codes aren't really the point.

as far as I can tell, random error codes are defined in random files, so you can't just search one file, I can't find a help document that just lets you search for an error code to get more info, and from what I can tell, in OS X you can use GetMacOSStatusErrorString() to convert an error to something useful, but there is no iPhone equivalent?

any help would be greatly appreciated.

EDIT:

ok, so casting them gives them in reverse (something I checked for 'mrep' but was not there either way round) , fmt? is in the list for the Audio Converter api, and is pretty self explanatory if a bit vague, but fair enough, still 'perm' isn't there (although it might be something to do with the simulator not supporting aac decoding) and my general question still stands.

like image 300
matt Avatar asked Feb 04 '10 01:02

matt


2 Answers

OSStatus is a signed integer value. You cannot convert or "cast" it to a string. You can convert it to a NSError like this:

NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:osStatus userInfo:nil];

like image 177
tomk Avatar answered Sep 28 '22 17:09

tomk


No. Not completely.

Some OSStatus are four-character-codes, so you can use (extracted from iPhone SDK's sample code "CAXException.h")

static char *FormatError(char *str, OSStatus error) {     // see if it appears to be a 4-char-code     *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);     if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {         str[0] = str[5] = '\'';         str[6] = '\0';     } else {         // no, format it as an integer         sprintf(str, "%d", (int)error);     }     return str; } 

(See iOS/C: Convert "integer" into four character string for some more ways to convert fourcc into string, including Swift)

NSError's NSOSStatusErrorDomain is able to decode some OS errors. See @tomk's answer.

If you don't need to decode the number in program for the user, you may use the macerror script to manually find out the meaning, as mentioned in @lros's answer. The list of OSStatus supported can be found from its source code in /System/Library/Perl/Extras/5.18/Mac/Errors.pm.

There is also an online service http://osstatus.com/ collecting errors from all public frameworks. They are still not really complete e.g. the mapping to -12792 mentioned in the comment is missing. Probably it is a code from a private framework.

like image 41
kennytm Avatar answered Sep 28 '22 17:09

kennytm