Thursday, December 13, 2007

[RESOLVED] Mail Scripting Error

OK, situation normal again.

The quest for possible coding errors ensuing from the subject of my last post resulted in the following lines of investigation:
Q. Is there any way I can find what the -10000 error code means?
A. Searched (local and Google) for applescript errors and internal Mail errors: nada.

Assumption: Having checked and rechecked the code a half-dozen times, it's most likely that this is Mail saying something is wrong with its internal state. i.e. I'm driving the Script Bridge right, but setting up Mail _wrong_ (and of course I can do this because of the loose coupling I was referring to before).

Action: Recheck the Mail applescript dictionary for clues.

Result: I discovered that there are (confusingly) several kinds of 'recipient' element to the 'outgoing message' class. In fact there are: recipients, bcc_recipients, cc_recipients and to_recipients. Similarly, there are separate classes for each of these.

Having instantiated an 'outgoing message', I had been creating a 'recipient' and adding this to the 'recipients' element of the message (at which point... BOOM!). The documentation (applescript dictionary) makes no differentiation between these except in the inane style "bcc_recipient: An email recipient in the Bcc: field". I had just picked the seemingly generic 'recipient' and 'recipients' list - but on reexamination, decided that there was a chance that the correct thing was 'to_recipient' and 'to_recipients'. Sure enough... it all works now.

So, as expected, the fix was pretty trivial once the problem was correctly diagnosed. However, in these dynamic programming systems, clear documentation, clear intentions and good samples are essential. Clear (useful) errors would go a long way to make up for some deficiencies in the foregoing too, as they would at least help you narrow down to the crux of problems and quickly converge on the correct code.

Anyway... that's one more bit of experience to store away for next time.

No comments: