Debugging for fun & profit (was: Why won't this parse?)
Debugging for fun & profit (was: Why won't this parse?)
- Subject: Debugging for fun & profit (was: Why won't this parse?)
- From: Sun Real <email@hidden>
- Date: Fri, 11 May 2001 13:49:51 +1000
David Graham's message of 11/5/01 7:02 AM contained:
>
At 2:15 PM -0500 5/10/01, Jolly Roger wrote:
>
>If it still doesn't work after you fix your misuse of the ASCII commands as
>
>we have suggested, please post again about the problem, since surely your
>
>results will have changed.
>
>
I guess I haven't been clear. I HAVE fixed the ASCII issue in my code, but
>
the problems persist! Now what???
Hmm. That's a bit odd. Like others who looked at your problem, I fixed
the tids error and the code worked fine after that. It errors on the
*last* time through the repeat, but that's because your last paragraph is
empty and therefore contains no second text item no matter what you set
the tids to. That, as Arthur suggested, may be what you hit.
It's often very easy to overlook the obvious - I certainly do it on a
regular basis - and to protect myself and others from my own stupidity, I
try to use the notion of "Don't assume it. Prove it!" If you really,
actually, seriously do this (not a trivial undertaking IMO) you will
always find the problem eventually and if you do it as you write, it
should reduce your debugging time significantly. One of the ways I try
to implement this is by logging things as I go, to make sure my variables
actually contain what I 'know' I set them to.
If you log 'thisEntry' straight after you declare it, then log 'text item
1 of thisEntry' straight after you declare that, you'll get a record of
it in the Log window of Script Editor for each repeat. Mine looked like
this:
(*thisEntry: alias PWI_AAA email@hidden*)
(*text item 1 of thisEntry: alias*)
(*thisEntry: alias PWI_BBB email@hidden*)
(*text item 1 of thisEntry: alias*)
(*thisEntry: alias PWI_CCC email@hidden*)
(*text item 1 of thisEntry: alias*)
(*thisEntry: note PWI_AAA All San Diego Employees*)
(*text item 1 of thisEntry: note*)
(*thisEntry: note PWI_BBB All San Bernardino Employees*)
(*text item 1 of thisEntry: note*)
(*thisEntry: note PWI_CCC All South Bay Employees*)
(*text item 1 of thisEntry: note*)
(*thisEntry: *)
(*text item 1 of thisEntry: *)
--> Can't get text item 2 of "".
To avoid the empty paragraph error, you could test for the paragraph's
contents before you try to parse it, i.e. make the first line after the
repeat declaration something like this:
if thisEntry is not "" then
-- do everything, put all your code here
else
-- do nothing, it's empty, ignore it
end if
Below is a copy of the script I use to log variables for debugging. I
use it in Script Editor, running from the OSA Menu. It would require
OS8.5 or higher, or Jon's Commands (for the clipboard command).
Double click your variable to select it, then make a new line where you
want to log its contents. Run the script below, then paste the log
statement into your empty line.
Beware of line wraps, Server Mangulation(TM) and strangers offering
sweets.
-- Log this variable... -- Richard Morton 1999-2001
-- writes a log string using the clipboard's contents as the variable
name
-- idea taken from a package called Script Sets (I think) I got from
Apple &
-- were probably written by Sal Soghoian
on run
display dialog "Use the clipboard contents as the variable to be
logged?" buttons <option L>
{"Cancel", "Yes"} default button 2 with icon 1
set varName to the clipboard
set the clipboard to "log \"" & varName & ": \" & " & varName
beep
end run
R23 has some cool code for logging variables in a literal form - lists
log as lists, not strings for eg - so you might want to check this out if
you're going to log complex data.
Cheers,
Richard Morton
-- Wondering if software is so unreliable because programmers smoke hash
tables...