Those pesky core audio error codes

11th Mar, 2015 | unix xcode

We've all been there. I was there recently with an error code from core audio, '-66748' to be specific. On a good day the meaning for these codes can be found in the core audio header files but this must be done by hand, unless there is some framework global search facility in XCode that no-one has told me about.

This time I thought I'd be slightly more automated and grep the framework header directory to search everything for me.

So with a right click on the framework and "Show in Finder" to get the path I tried

grep -r "-66748" /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

grep: warning: recursive search of stdin

Eh?

I've specified the path so why is grep reading stdin?

Turns out it's the negative error code, despite being in quotes. The dash is making -66748 a grep argument, rather than the search term.

The trick to fix this is to use a double dash — to indicate to the shell there are no further optional arguments to parse after the -r option.

This comes up with the goods:

grep -r -- "-66748" /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AUComponent.h: kAudioComponentErr_NotPermitted = -66748,

and a bit of extra grep arguments to show line numbers and context:

grep -nr -C 2 -- "-66748" /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AUComponent.h-809- kAudioComponentErr_TooManyInstances = -66750,

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AUComponent.h-810- kAudioComponentErr_InstanceInvalidated = -66749,

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AUComponent.h:811: kAudioComponentErr_NotPermitted = -66748,

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AUComponent.h-812- kAudioComponentErr_InitializationTimedOut = -66747,

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AUComponent.h-813- kAudioComponentErr_InvalidFormat = -66746

Or why not put it in a script?

#!/bin/bash

if [ "$#" -ne 1 ]
then
    echo "Usage $0 "
    exit 1
fi

grep -nr -C 2 -- "$1" /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks