Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
Hi,

I wonder if anyone know of a function that will take my OSStatus error code and return a string that makes more sense.

I have found a apple utility but, it's c++ and my whole program is in c. I'm not rewriting it to compile in c++ just to get a comprehensible string from this obscure number.

Surely there must be a function just for this in Carbon or CoreFoundation right?
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
I'm not sure without looking, but why not just rewrite the c++ code from Apple?

EDIT: after a quick search are neither of these useful?
const char* GetMacOSStatusErrorString(OSStatus err);
const char* GetMacOSStatusCommentString(OSStatus err);

in CoreServices/CarbonCore/Debugging.h
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
Thanks for that. It seems to work, but the strings it returns are unfortunately empty. This is for core audio, and perhaps the empty strings are the reason for the existence of the error handling utility header. I might have to do as you first suggested and try to get some sense from the header file.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Hi,

I wonder if anyone know of a function that will take my OSStatus error code and return a string that makes more sense.

I have found a apple utility but, it's c++ and my whole program is in c. I'm not rewriting it to compile in c++ just to get a comprehensible string from this obscure number.

Surely there must be a function just for this in Carbon or CoreFoundation right?

Do you think you will get a comprehensible string out of an OSStatus anyway? The best you can expect is a sequence of English words that leaves your user just as baffled as an obscure number. The obscure number, on the other hand, has a better chance to be reported back to you correctly, giving you a chance to fix the problem.
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
Do you think you will get a comprehensible string out of an OSStatus anyway? The best you can expect is a sequence of English words that leaves your user just as baffled as an obscure number. The obscure number, on the other hand, has a better chance to be reported back to you correctly, giving you a chance to fix the problem.

I don't know really, but the purpose here is to get some insight (for me) why a function call returns err. I'm doing something wrong obviously but, was hoping for something more than what I get with my own macro, that does nothing more than exit the application and tell me which function returned the error code.
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
What are your error numbers? Can you find them in MacErrors.h?

Thanks. I had a look at MacErrors.h but did not find it there. I noticed that all numbers where negative and a great deal smaller than what I get if I print my number however. I'm not sure if there is a corresponding string or if apples macro simply terminates and does some house keeping with allocated resources, closing files etc. then exits. Never mind though, I have to take a closer look at the documentation, I'm sure I'm doing something wrong when I make my function call. Thanks for the help and suggestions.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
Thanks. I had a look at MacErrors.h but did not find it there. I noticed that all numbers where negative and a great deal smaller than what I get if I print my number however. I'm not sure if there is a corresponding string or if apples macro simply terminates and does some house keeping with allocated resources, closing files etc. then exits. Never mind though, I have to take a closer look at the documentation, I'm sure I'm doing something wrong when I make my function call. Thanks for the help and suggestions.

Please be specific.

Post examples of the error numbers. Post the exact names of the functions returning those errors. Exactly which Apple macro are you talking about?

You said you were working with Core Audio. It has a number of error-codes that will appear to be obscure and discontiguous in any numerical sense. These are all defined as 4-char-constants in AudioHardware.h. For example:
Code:
    kAudioHardwareBadObjectError                = '!obj',
    kAudioHardwareBadDeviceError                = '!dev',
    kAudioHardwareBadStreamError                = '!str',
    kAudioHardwareUnsupportedOperationError     = 'unop',
    kAudioDeviceUnsupportedFormatError          = '!dat',
    kAudioDevicePermissionsError                = '!hog'
That file also has this comment:
Note that the HAL's functions can and will return other codes that are not listed here.
AFAIK, some of those other codes are also formed as 4-char-constants.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
You could try CFError. Use CFErrorCreate(), passing in the domain kCFErrorDomainOSStatus and your OSStatus value. Then see if CFErrorCopyDescription() returns anything useful. However, I would be surprised if that worked with Core Audio values but you could give it a shot.
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
Thanks kainjow. That's pretty clever, tried it but as you predicted the string is empty in this case as well. I will look over the code to see what is wrong my self.

chown33, I guess I was looking for a quick answer, just to cover if there was a function to do what I had in mind here. But, the macro I was referring to is XThrowIfError in CAXException.h. The error code in my case is: 1768846202 which comes down to 'zsni' if interpreted as 4 chars.

Thanks.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
In <AudioToolbox/AudioConverter.h>

Code:
kAudioConverterErr_InvalidInputSize = 'insz',
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Thanks kainjow. That's pretty clever, tried it but as you predicted the string is empty in this case as well. I will look over the code to see what is wrong my self.

chown33, I guess I was looking for a quick answer, just to cover if there was a function to do what I had in mind here. But, the macro I was referring to is XThrowIfError in CAXException.h. The error code in my case is: 1768846202 which comes down to 'zsni' if interpreted as 4 chars.

Thanks.

What does the debugger say when you use "display as OSType"?
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
What does the debugger say when you use "display as OSType"?

Gnasher, that seems like a good idea. I have not used that feature in Xcode and looking at it all the options are grey, except "Use Data Formatters" in the variables view menu. Any Idea how I can access them?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.