Re: Maintaining Large Scripts
Re: Maintaining Large Scripts
- Subject: Re: Maintaining Large Scripts
- From: Paul Skinner <email@hidden>
- Date: Mon, 13 Aug 2001 12:25:03 -0400
on 8/13/01 10:06 AM, Bourque, Jason wrote:
>
Hello,
>
>
I have a Script Server Applet that Launches other scripts and tells them to
>
work. Ten+ scripts are triggered this way.
>
>
My problem is that my tech support personel have limited knowledge of AS and
>
I want them to see the errors better.
>
>
Errors are hidden when called from a different script or when the script is
>
over 32k the script editor is unable to select the line that is the error.
>
>
Does anyone have any opinions on how to effectively support scripts launched
>
this way or have another way of triggering scripts and sending them
>
parameters?
>
>
Thanks,
>
>
Jason Bourque
A while back ( caveat: Old code. ) I wrote a 'displayErrorMessage'
handler to display a dialog with information about any error that occurred
inside other handlers that are loaded from a library. It takes data from an
on error statement as parameters...
I don't launch scripts from a script server, but you should be able to
do something very similar. Logging the output to a text file for unmanned
script boxes shouldn't be hard either. Here's what I did, hope it helps
spark something...
try
4 as alias
on error errorMessage number errorNumber partial result errorResult from
errorFrom to ErrorTo
end try
displayErrorMessage({errorGeneratingHandlersName:"this script's name",
errorMessage:errorMessage, errorNumber:errorNumber, duration:30})
on displayErrorMessage(parameters)
--on displayErrorMessage(parameters)
----------------------------------------------------------------------------
-->>DESCRIPTION:<<
--displayErrorMessage(parameters)
--FUNCTIONDisplays an error message that includes the name of the
handler or script
--that caused the error, the text error message, and the error number.
--This handler will allow you to return to the offending handler or
'Force Quit' it.
--GIVEN{[errorGeneratingHandlersName], [errorMessage],
[errorNumber],[duration]}
-- > errorGeneratingHandlersNameThe calling script or handler. <string>
-- > errorMessageThe text explanation of the error. <string>
-- > errorNumberThe number of the error. <string>
-- > durationThe number of seconds that the error message persists.
<integer>
--RETURNStheResults
-- > theResults{errorMessageDisplayed:boolean} <Boolean>
-- > Returns 'false' if an error is generated.
----------------------------------------------------------------------------
-->> VARIABLE DECLARATIONS:<<
--set aVariable to aValue --aVariableDescription
set thisHandlersName to "displayErrorMessage" --The name of this
handler.
set theResults to {errorMessageDisplayed:true} --The results will be
'true' unless an error sets it to 'false'
--Set variables to parameters, or defaults if they are not provided.
try
set errorGeneratingHandlersName to errorGeneratingHandlersName of
parameters as text
on error
set errorGeneratingHandlersName to "Unknown handler or script"
end try
try
set errorMessage to errorMessage of parameters as text
on error
set errorMessage to "Unknown error "
end try
try
set errorNumber to errorNumber of parameters as text
set errorNumberText to "Error number: "
on error
set errorNumber to ""
set errorNumberText to ""
end try
try
set duration to duration of parameters as integer
on error
set duration to 60
end try
----------------------------------------------------------------------------
-->>BODY:<<
try --Handle any errors not handled in the BODY code.
--handle errors generated by a calling handler or script
if errorNumber = -128 then
--On a user cancellation explain the termination of the script.
tell me
activate
display dialog "You have canceled " & return & "'" &
thisHandlersName & "'" buttons {"Ok"} default button "Ok" with icon 0 giving
up after duration
end tell
else
--On an unhandled error in the BODY display error message
set errorText to " Script Error:" & return & return & "'" &
errorGeneratingHandlersName & "'" & return & "has returned an error." &
return & return & " " & errorMessage & return & return & errorNumberText &
errorNumber
tell me
activate
display dialog errorText buttons {"Force Quit", "Ok"}
default button "Ok" with icon 0 giving up after duration
end tell
set thereply to button returned of result
if thereply = "Force Quit" then
set warningText to "You have chosen to " & thereply & "." &
return & return & "This may leave the calling object waiting for a
response." & return & return & "Are you sure that you want to " & thereply &
return & "'" & errorGeneratingHandlersName & "' ?" & return & return
tell me
activate
display dialog warningText buttons {(thereply as text),
"Handle the Error"} default button "Handle the Error" with icon 2 giving up
after duration
end tell
set theSecondReply to button returned of result
if theSecondReply = thereply as text then
quit
end if
end if
end if
----------------------------------------------------------------------------
--Handle any errors not handled in the BODY code.
--This handles errors generated internally by this handler.
on error errorMessage number errorNumber
try
if errorNumber = -128 then
--On a user cancellation explain the termination of the
script.
tell me
activate
display dialog "You have canceled " & return & "'" &
thisHandlersName & "'" buttons {"Ok"} default button "Ok" with icon 0 giving
up after duration
end tell
else
--On an unhandled error in the BODY display error message
set errorText to " Script Error:" & return & return & "'" &
errorGeneratingHandlersName & "'" & return & "has returned an error." &
return & return & " " & errorMessage & return & return & "error number: " &
errorNumber
tell me
activate
display dialog errorText buttons {"Force Quit", "Ok"}
default button "Ok" with icon 0 giving up after duration
end tell
set thereply to button returned of result
if thereply = "Force Quit" then
set warningText to "You have chosen to " & thereply &
"." & return & return & "This may leave the calling object waiting for a
response." & return & return & "Are you sure that you want to " & thereply &
return & "'" & errorGeneratingHandlersName & "' ?" & return & return
tell me
activate
display dialog warningText buttons {(thereply as
text), "Handle the Error"} default button "Handle the Error" with icon 2
giving up after duration
end tell
set theSecondReply to button returned of result
if theSecondReply = thereply as text then
quit
end if
end if
end if
on error
set appologyText to ((" Script Error:" & return & return & "The
handler" & return & "'" & thisHandlersName & "'" & return & " has generated
an error" & return & "which it cannot display." & return & return & return &
"Isn't that ironic?") as text)
tell me
activate
display dialog appologyText buttons {"Umm, yeah"} default
button "Umm, yeah" with icon 0
end tell
end try
set theResults to false
end try
----------------------------------------------------------------------------
--Return the results of the handler. ('false' if there was an error or
cancellation.)
return theResults
--end displayErrorMessage
end displayErrorMessage
--
"AppleScript is digital duct tape."
Paul Skinner