Monday, January 7, 2008

21st Century Errors and Apple Script

Playing with NSAppleScript, I'm currently befuddled by -compileAndReturnError returning the following:
{
NSAppleScriptErrorNumber = -1700;
}

Nice.

NSAppleScript.h has no error codes listed, and a search (so far) has turned nothing up.

Actually, about half the time, the particular lines of code (run on the main thread of course, as required by NSAppleScript):

NSDictionary *errors;
[script compileAndReturnError:&errors];

will actually crash the application with the stack:

#0 0x923dfd7c in getDescDataType
#1 0x923e3ad7 in aeCoerceDescInternal
#2 0x923e8075 in AECoerceDesc
#3 0x005ae150 in ComponentCoerceDesc
#4 0x00592bec in ASCompile
#5 0x9600b5bc in CallComponentFunction
#6 0x0058dae2 in AppleScriptComponent
#7 0x005a9927 in AGenericManager::HandleOSACall
#8 0x95fc5ef5 in CallComponentDispatch
#9 0x923cd513 in OSACompile
#10 0x92d84eff in -[NSAppleScript compileAndReturnError:]
...
#23 0x9577692e in NSApplicationMain
#24 0x00002b84 in main at main.m:13

Double nice.

The source with which the script has been initialised has variously been:
"current date"
"beep 2"
and
"tell current application to beep 2"

The opaqueness of the error message, not to mention the intermittent crash, suggests that this one is going to take some attrition to actually chase down. What fun. Watch this space...

2 comments:

Unknown said...

-1700 = errAECoercionFail ('bad parameter data or unable to coerce the data supplied').

See MacErrors.h in CarbonCore.framework for a full run-down of Carbon error codes. The API reference docs for the Carbon Apple Event Manager and Open Scripting Architecture APIs also list commonly encountered error codes.

Luke Evans said...

Again, much obliged.

The problem I'm having (bad interaction with GC) is apparently already known to 1 Infinite Loop.

Nice to know where the err codes are (I was a bit blinkered by Cocoa and should remember to search down into the core framework layer for things like this).