Adobe Illustrator ASOC and random errors

I have building a helper tool for some repetitive tasks in adobe illustrator using ASOC.
I randomly throw errors while trying to do the following.

on createSwatches()
        tell application "Adobe Illustrator"
            if not (exists swatchgroup "specialColors" in current document) then
                make new swatchgroup in current document with properties ¬
            end if
            createColorSwatch("glosswhite",232.0,233.0,236.0,"specialColors") of me
            createColorSwatch("mattewhite",232.0,233.0,236.0,"specialColors") of me
            createColorSwatch("glossblack",16.0,15.0,17.0,"specialColors") of me
            createColorSwatch("matteblack",16.0,15.0,17.0,"specialColors") of me
            createColorSwatch("orange",226.0,77.0,37.0,"specialColors") of me
            createColorSwatch("red",182.0,32.0,37.0,"specialColors") of me
            createColorSwatch("yellow",255.0,199.0,10.0,"specialColors") of me
            createColorSwatch("goldenyellow",251.0,170.0,25.0,"specialColors") of me
            createColorSwatch("softpink",242.0,133.0,179.0,"specialColors") of me
            createColorSwatch("hotpink",201.0,43.0,106.0,"specialColors") of me
            createColorSwatch("brown",64.0,47.0,29.0,"specialColors") of me
            createColorSwatch("mint",99.0,197.0,180.0,"specialColors") of me
            createColorSwatch("yellowgreen",32.0,152.0,71.0,"specialColors") of me
            createColorSwatch("darkgreen",0.0,63.0,40.0,"specialColors") of me
            createColorSwatch("goldmetallic",119.0,98.0,49.0,"specialColors") of me
            createColorSwatch("silvermetallic",106.00,107.0,108.0,"specialColors") of me
            createColorSwatch("skyblue",4.0,115.0,187.0,"specialColors") of me
            createColorSwatch("blue",32.0,62.0,118.0,"specialColors") of me
            createColorSwatch("purple",67.0,42.0,113.0,"specialColors") of me
            createColorSwatch("lightgrey",192.0,193.0,191.0,"specialColors") of me
            end tell
        end createSwatches

what I thought would be straight forward…randomly throws an error
it seems to generate a good deal of the swatches when this happens but misses a few of the last ones…

“Adobe Illustrator got an error: an Illustrator error occurred: 1346458189 (‘MRAP’) (error 1200)”

I’ve researched this a bit and found the following…
“An Illustrator error occurred: 1346458189 (‘PARM’)” alert (1459349)

Affects: JavaScript

This alert may be popped when badly written scripts are repeatedly
run in Illustrator from the ExtendScript Toolkit

Scripters need to be very careful about variable initialization and 
namespace conflict when repeatedly pushing a batch of Illustrator scripts
for execution in Illustrator via the ExtendScript Toolkit (ESTK) in a 
single Illustrator session. Each script run is executed within the same 
persistent ExtendScript engine within Illustrator. The ESTK debugger 
uses BridgeTalk to communicate with Illustrator. One global, persistent 
ExtendScript engine inside Illustrator handles all BridgeTalk 
communications. The net effect is that the state of the ExtendScript 
engine is cumulative across all scripts that ran previously.

The following issues with script code can cause this problem:

  - Reading uninitialized variables. 
  - Global namespace conflicts, like when two globals from different
    scripts clobber each other.

Initialize variables before using them, and consider the scope of
your variables carefully. For example, isolate your variables by
wrapping them within systematically named functions. Instead of:

  var myDoc = app.documents.add();
  // Add code to process myDoc

Wrap myDoc in a function that follows a systematic naming scheme:

  function myFeatureNameProcessDoc() {
var myDoc = app.documents.add();
// Add code to process myDoc

However none of that makes sense as I’m not using javascript, nor am I really doing anything complicated.
Any insight could greatly help me out! THANKS!

That sounds odd. How are you making the swatches – are you using actions at all?

Whoops! Completely forgot the createColorSwatches

  on createColorSwatch(colorName, redColor, greenColor, blueColor, groupName )
        tell application "Adobe Illustrator"
            make new swatch in current document with properties ¬
        {name:colorName, color:{red:redColor, green:greenColor, blue:blueColor}}
        set sGroup to swatchgroup groupName of current document
        set theSwatch to swatch colorName of current document
        add swatch sGroup ¬
        swatch theSwatch
        end tell
    end createColorSwatch

There doesn’t seem to be anything suspicious there. How odd.

Yup! Exactly…

Is there an easy way to log xcode console from within an Adobe Illustrator tell?

Not directly – you need to call a handler, and you can’t log Illustrator objects.