Skip to content

Instantly share code, notes, and snippets.

@silverjam
Created August 24, 2010 17:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silverjam/547970 to your computer and use it in GitHub Desktop.
Save silverjam/547970 to your computer and use it in GitHub Desktop.
$ ./osstatus -108
Error number: -108 / 0xffffff94
Error string: memFullErr / iMemFullErr
Error description: Not enough room in heap zone /
#!/usr/bin/env python
"""
Convert OSStatus to a human readable string.
"""
import sys
from ctypes import *
def die_with_usage():
sys.stderr.write("Usage: %s <ERROR_CODE>\n" % sys.argv[0])
sys.exit(1)
if len(sys.argv) < 2:
die_with_usage()
try:
err = int(sys.argv[1])
except ValueError:
die_with_usage()
cs = CDLL(
"/System/Library/Frameworks/CoreServices.framework"
"/Versions/Current/CoreServices"
)
print('Error number:\t\t%d / 0x%x' % (err, c_uint32(err).value))
cs.GetMacOSStatusErrorString.restype = c_char_p
errorString = cs.GetMacOSStatusErrorString(c_uint32(err))
print('Error string:\t\t%s' % str(errorString))
cs.GetMacOSStatusCommentString.restype = c_char_p
errorDesc = cs.GetMacOSStatusCommentString(c_uint32(err))
print('Error description:\t%s' % errorDesc)
@silverjam
Copy link
Author

$ ./osstatus -108
Error number: -108 / 0xffffff94
Error string: memFullErr / iMemFullErr
Error description: Not enough room in heap zone /

@joaoe
Copy link

joaoe commented Feb 22, 2013

If you use int(value, 0), then the script interprets hex easily as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment