A Tragedy of Errors was Re: handler failure
A Tragedy of Errors was Re: handler failure
- Subject: A Tragedy of Errors was Re: handler failure
- From: Paul Skinner <email@hidden>
- Date: Tue, 12 Nov 2002 20:58:19 -0500
Our story opens with an gentle AppleScripter who stumbles over a
difficulty.
On Tuesday, November 12, 2002, at 10:14 AM, Mario Kolaszewski wrote:
What can cause a handler to execute successfully.
And fail on the second run citing the following error:
'script' doesn't understand the 'handlersName' message
Mario.
On Tuesday, November 12, 2002, at 11:11 AM, I, your humble narrator,
being a kind and helpful soul; replied...
Been there!
Got this nifty t shirt...
...I set my handler variable to a value and all I got was this lousy
value.
ie.
repeat 2 times
doSomethingCool()
end
--> one good loop then... +script; doesn't understand the
doSomethingCool message.
on doSomethingCool()
set doSomethingCool to "@*%^!!!"
end
--
Paul Skinner
Because, in the past, when I had any handler that worked once and then
failed with an error stating that the script doesn't know how to do
that thing that it just did a millisecond ago it was always because I
had stupidly set the variable containing the handler to a new value.
I thought that this script would show Mario the problem that I was
sure that he was having. Since there really wasn't anything helpful in
Mario's post I didn't quote it. Big mistake.
Moments later, at 11:27 AM, Gary wrote:
Paul Skinner <email@hidden> said, on 11/12/02 11:11 AM:
repeat 2 times
doSomethingCool()
end
--> one good loop then... +script; doesn't understand the
doSomethingCool message.
on doSomethingCool()
set doSomethingCool to "@*%^!!!"
end
Same error for me.
I try this and it works fine.
--
set withthis to ""
repeat 2 times
set myclip to doSomethingCool(withthis)
end repeat
on doSomethingCool(withthis)
set withthis to "@*%^!!!"
return withthis
end doSomethingCool
--
Gary
Hmmm, I hadn't quoted Mario, and as a result Gary hadn't realized that
I was trying to show Mario the error in his unposted script. So Gary
had posted code that would work, confirming that mine was indeed; bad
code.
Well, this wouldn't do at all! I tried to clear up this
misunderstanding when, at 12:11 PM, I wrote:
On Tuesday, November 12, 2002, at 11:27 AM, Gary wrote:
Paul Skinner <email@hidden> said, on 11/12/02 11:11 AM:
snip
Same error for me.
I try this and it works fine.
Maybe it wasn't obvious, but I was trying to make the error obvious.
It was supposed to fail.
And I had hoped that it would make it obvious why it fails.
Did it?
--
Paul Skinner
Now there came another post to this thread by Michael Sullivan. He
asked Mario some questions and then suggested that he post his code. I
hadn't asked for it because I felt that I knew what had happened to
Mario. I'd been there.
Now, I thought that things were cleared up until on Tuesday, November
12, 2002, at 01:36 PM, Gary wrote:
Michael Sullivan <email@hidden> said, on 11/12/02 1:02 PM:
If it's really doing this from one run to the next and you haven't
changed *anything*, can you post the script?
He did, here it is again..
And also, in a message or post titled
[ Re: handler failure ],
Paul Skinner <email@hidden> wrote:
repeat 2 times
doSomethingCool()
end
--> one good loop then... +script; doesn't understand the
doSomethingCool message.
on doSomethingCool()
set doSomethingCool to "@*%^!!!"
end
Oh No! Now it was even worse than before! Now the question had been
attributed to me! And here I thought that I had been so clever as to
see the problem right off like that, and to be able to answer without
even seeing the code. Now, I was this guy who didn't even see the
GLARING error in this oh-so-simple script. How did this all happen?
This is all just before Mario Kolaszewski wrote back on Tuesday,
November 12, 2002, at 02:59 PM,:
thanks for everyone's input...
Removing an 'If' statement, which was already handled by a previous
handler
seemed to have corrected the problem.
Puzzling?
Mario
This totally obsfucates the whole thing! Trechery! Conspiracy?
Paul Berkowitz replied to Mario and told him how people make mistakes
all the time, but without any code to look at, no one can help him
understand why it was broken or what fixed it. auuuugggghhhh,
Finally, when I check mail at home, I see that On Tuesday, November
12, 2002, at 04:20 PM, Kai Edwards wrote:
on Tue, 12 Nov 2002 12:11:08 -0500, Paul Skinner <email@hidden>
wrote:
Maybe it wasn't obvious, but I was trying to make the error obvious.
It was
supposed to fail. And I had hoped that it would make it obvious why
it fails.
Did it? --
Just to reassure you, Paul - I believe your script illustrated the
problem
pretty well. I tried something similar once out of idle curiosity.
Fortunately, the experiment didn't quite kill the cat (though my
reaction
may have startled it a little) - but it sure did teach me the value of
distinguishing between my handler and variable naming conventions. ;-)
Best wishes.
Kai
Whew!
At least I'm not completely into the twilight zone yet. I can still
explain all of this. Right?
So, I'm just resolving to 'Always attribute the original!' and let the
thread die, because it's probably worse to try to fix it at this point,
when...
Chris Espinosa, who works at Apple.
No, who works on the AppleScript team.
No, Who LEADS the AppleScript team at Apple wrote:
On Tuesday, November 12, 2002, at 11:37 AM, Paul Skinner
<email@hidden> said, on 11/12/02 11:11 AM:
wrote:
repeat 2 times
doSomethingCool()
end
--> one good loop then... +script; doesn't understand the
doSomethingCool message.
on doSomethingCool()
set doSomethingCool to "@*%^!!!"
end
AppleScript is not Pascal.
OH! no, Wait, I...
To return a value from a function, you use
the Return command:
on doSomethingCool()
return "@*%^!!!"
end
Aughhhhuugghhhhh! But, I...
What you're doing is replacing the doSomethingCool function with the
string "@*%^!!!". Once that happens, you script consists of a default
Run handler and a string, instead of a default Run handler and a
doSomethingCool() function, so the call to the now-nonexistent function
fails.
A handler is essentially a property in your script, and you can set it
to any value, including that of another function. For example:
on f1()
return 1
end f1
on f2()
return 2
end f2
on temp() -- placeholder
end temp
on run
set temp to f1
set r1 to temp()
set temp to f2
set r2 to temp()
{r1, r2}
end run
Chris Espinosa
Apple
Aaaarrrrrrrggghhhhhuuughhhaahh!!!!
Et tu . . . Chris?
...curtain closes...
( fade dead: )
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.