IS: Debugging Techniques -- WAS: Re: cure for NSArgumentEvaluationScriptError?
IS: Debugging Techniques -- WAS: Re: cure for NSArgumentEvaluationScriptError?
- Subject: IS: Debugging Techniques -- WAS: Re: cure for NSArgumentEvaluationScriptError?
- From: Johnny AppleScript <email@hidden>
- Date: Wed, 22 Sep 2004 16:35:25 -0600
Title: IS: Debugging Techniques -- WAS: Re: cure for NSArgumentEvaluationScriptError?
On 04/09/21 9:30 PM, "Robert Poland" <email@hidden> wrote:
> In my continuing search for the cure to NSArgumentEvaluationScriptError...
> I'm trying plugging in the following.
>
> on error errMSG
> log errMSG
>
> I had thought the log would be in the Smile Console window, wrong.
> Any clues where the msg will appear?
>
> Help understanding the use of "errMSG" would be appreciated.
Hi Bob,
I have a feeling that my similar frustrations with dealing with intermittent transient errors might help you here.
First of all, and I think that at least by now you realize that ‘log’ commands only appear in Smile's Console or Script Editor's Event Log when the applications/scripts are run in those environments. If I recall correctly, your task is run as either a compiled script or app, and you are getting an error dialog, but not always, and no other clues as to reason are provided.
What I have done to deal with this is take advantage of other OS X tools, and also employ multiple attempts to various sections of scripts that are more heavily divided than I would otherwise write. This seems to deal with transient errors pretty well; usually the kind of error you're receiving, as Paul B. pointed out, can occur once in a moon and can be difficult to repeat, or it can occur once in every three runs, but with no rhyme or reason. Liberal use of try blocks, and optional logging tools are the approach I would take here. Please note that I have included four logging options, you do not have to use all of them.
HTH
JA (who isn’t thrilled with adding so much to scripts that should otherwise be simple, but it deals with the problem well)
global qt, appName, consoleLOG, applicationLOG, myThingCount
set qt to "\"" -- we need escaped quotes in shell scripts
set appName to "My_Troublesome_Application_Name" -- use a name that you or your user can easily identify
(* IMPORTANT: be sure the name above does not have spaces when specifying the user directory path below *)
set applicationLOG to "~/Library/Logs/" & appName & ".log"
(* usually you want to log only within the user account, unless the app is shared by all users on the same system
at the same time, or a sysadmin will need to review application errors from outside the current user environment;
in that case, use "/Library/Logs/" *)
set userName to do shell script "whoami" -- get the shortname of the current user
set PantherconsoleLOG to "/Library/Logs/Console/" & userName & "/Console.log" -- Panther uses individual console logs
set JaguarConsoleLOG to "/var/tmp/Console.log" -- Jaguar uses one general log
set OSversion to my GetSystemVersion() -- which OS are we using?
if OSversion < 10.3 then set consoleLOG to JaguarConsoleLOG
if OSversion 10.3 then set consoleLOG to PantherconsoleLOG
set myThingCount to 0 -- we start counting attempts at 0
my myThing()
on myThing()
set myThingCount to myThingCount + 1 -- add one for every time we try this whole routine
if myThingCount < 5 then -- how many times should we try a subroutine before we give up?
try
1 / 0
on error errorMessage number errorNumber
log "ERROR!" -- I like to add this extra bit here because it stands out in formatted text better than the following:
set basicErrorMessage to "ERROR:" & errorNumber & ": " & errorMessage as string
set fullErrorMessage to "[" & (current date) & "] " & basicErrorMessage
(* we now can log the error message in one of four, or all four places: *)
log basicErrorMessage -- this alert appears in SE Event Log or Smile Console
my alertConsole(fullErrorMessage)
(*the above alert appears in console.log, which can be viewed in real time by opening console.log in
Console.app (/Applications/Utilities/Console.app) *)
my noteToLogfile(basicErrorMessage)
(* the above alert will appear in the named file path in your user directory for
the application as named above; if it does not exist, it will create one; you can use this in addition to,
or instead of the alertConsole; both logs are viewable in Console.app *)
my alertSystem(basicErrorMessage)
(* this last one above is the simplest, because it requires no version checking, no logile paths, no special file creation, etc.,
but many sysadmins frown on writing to system.log if the app is not system-related *)
(*Now, since we are hoping the error result is transient, we'll try again: *)
my myThing()
(* you could also trigger a re-attempt above only by displaying a dialog and acting on a button returned option *)
end try
else
set errorMSG to "Sorry, I've tried to perform myThing() " & myThingCount & " times now; I'm giving up." & return & return & ¬
"See '" & consoleLOG & "' or '" & applicationLOG & "' for more details."
(* you can do whatever you want here; if the overall script will fail without a
result from myThing(), then you should probably alert the user: *)
display dialog errorMSG with icon 0
(* if the script can continue without a valid result from myThing(), you may just want to log the failure to: *)
my alertConsole(errorMSG) -- carry the variable 'errorMSG' to alertConsole(message)
(* and / or : *)
my noteToLogfile(errorMSG) -- carry the variable 'errorMSG' to noteToLogfile(message)
(* and / or : *)
my alertSystem(errorMSG)
end if
end myThing
on alertConsole(message) -- any text string can be converted to 'message' and logged by this routine
try
do shell script "echo " & qt & appName & ": " & message & qt & " >> " & consoleLOG
on error errMsg
log "ERROR!" -- I like to add this extra bit here because it stands out in formatted text better than the following:
log errMsg -- we only need to log to Event Log here because we should only see errors while testing before deployment
end try
end alertConsole
on noteToLogfile(message) -- any text string can be converted to 'message' and logged by this routine
try
do shell script "echo " & qt & message & qt & " >> " & applicationLOG
on error errMsg
log "ERROR!" -- I like to add this extra bit here because it stands out in formatted text better than the following:
log errMsg -- we only need to log to Event Log here because we should only see errors while testing before deployment
end try
end noteToLogfile
on alertSystem(message) -- any text string can be converted to 'message' and logged by this routine
try
do shell script "logger -is " & quoted form of message
on error errMsg
log "ERROR!" -- I like to add this extra bit here because it stands out in formatted text better than the following:
log errMsg -- we only need to log to Event Log here because we should only see errors while testing before deployment
end try
end alertSystem
on GetSystemVersion()
tell application "Finder" to set SystemID to system attribute "sysv"
set {a, x} to {SystemID div 4096, SystemID mod 4096}
set {b, y} to {x div 256, x mod 256}
set {c, d} to {y div 16, y mod 16}
if a "0" then set b to "" & a & b
set OSversion to "" & b & "." & c & "." & d
end GetSystemVersion
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden