|
| 10.2 Dynamic Error Handling |
|
Logging elsewhere
Vortex error messages can be logged to another file besides the
default /usr/local/morph3/texis/vortex.log
. For
command-line scripts, the option -e
specifies where to log
them. For Web scripts, and to change the overall default log file,
the /usr/local/morph3/texis.cnf
file can be edited.
Stopping messages, capturing in-script
A script can monitor its own error messages to detect and
possibly correct errors on the fly. If a putmsg
script
function is present in a script, it will be called whenever errors
are generated. Several variables are set by Vortex when the
function is called. These variables are in a parallel loop, one
value per message, since several message may be queued up by the
time it's safe to call putmsg
:
- errnum
The error number
- errscript
The script file or module where the error occurred
- errline
The line in the script or module where the error occurred
- errmsg
The text of the message
- errfunc
The internal C function it occurred in
The Vortex function it occurred in
When putmsg
is defined, errors will go to that function,
and will not be logged or printed to the output. It is up to the putmsg
to dispose of the messages: log them, print them, warn the
user, etc. A sample putmsg
function that scans for specific
errors might look like this:
<A NAME=putmsg PRIVATE>
<LOOP $errnum $errscript $errline $errmsg $errfunc>
<strstr "<EXEC> command" $errmsg>
<IF $ret neq "">
<B>The EXEC failed</B>
<$BadExec = y>
</IF>
<B>$errnum $errscript:$errline $errmsg in $errfunc
</LOOP>
</A>
<A NAME=otherfunc>
<$BadExec = n>
<EXEC /no/such/program></EXEC>
<IF $BadExec eq "y">
<EXEC /some/other/program></EXEC>
</IF>
</A>
|
Here we scan the errors in putmsg
for messages about <EXEC>
failing. <EXEC>
runs external programs, so it
commonly generates errors, eg. if the program is not found or exits
with an error. We set the flag $BadExec
to y
if it
fails. Regardless of the error message, we print it out in bold so
we can see it.
In otherfunc
, we try to run /no/such/program
.
This fails, generating an error. putmsg
is thus called,
sees the <EXEC>
error, and sets our flag. We can then
check this flag back in otherfunc
: if our <EXEC>
failed, we try it again with a new path.
|