On Mon, 20 Mar 2000, Leo Butler wrote:
> Roberto Beccherle wrote:
>
> > In module there is an option called conflict to be used to catch
> > conflicts between already loaded modulefiles. I have to set up
> > modulefiles for two different versions of software so i have
> > something like:
> > Software/verA (default) and Software/verB
> > now in hte modulefiles i put the command conflict Software and if
> > i load a version once anotherone is already loaded modules dumps
> > an Error stating this fact (plus some other info) and exits.
> > My question is the following:
> > How do i catch the error message and instead of exiting dump
> > something nice to stderr or even better automatically unload the
> > other version and load the correct one telling the user i have
> > done so? Tcl provides catch but i was not able to use it... :(
>
> Hello, Roberto.
(Snip...)
>
> > In general how do i manage the errors eventualy produced by module?
>
> To the best of my knowledge, you don't. Maybe there's a really
> awesome method of capturing errors in Tcl that modules can work
> with, but I'm also no Tcl expert so I don't know if it can trap
> errors. I instead avoid the errors with "tricks" as above and
> call it good. Thanks go to Dave Barnett for giving me the help
> the other day which allowed me to work this out.
>
I found out a hopefully clever way to handle exceptions (errors) thrown in
module by commands like conflict, require etc.
You can indeed use catch and here is an example and how it works:
Suppose again you have two modulefiles in a directory like this:
Software/verA (default) and Software/verB
and you put ther following line in both verA and verB modulefiles
conflict Software
Now if you try to load one of this modules and one is already loaded modules
will complain twice:
Once writing the Error message provided by the conflict routine and a second
one coming from TCL stating that there has been an error and that the execution
of the script has been ended!
The catch command allows you to indeed trap this second error message and avoid
TCL from aborting the script.
For example in the following code what happens is the following:
set my_err [catch [conflict Software]]
if {$my_err} then {puts stderr "there was a conflict"} else {puts stderr "no
conflict "}
conflict Software is executed and the first error message is printed out
catch catches the error and returns a 1 which is set into my_err
(catch returns 0 if there has been no error) and suppresses the second error
Now in the if statement you can check for the error and do anything you like,
for example you could unload Software.
This method works for all errors produced by any TCL command i suppose...
In addition if you put the following line in your modulefile (after having
debugged it of course :)
module-log error none
you can also get rid of the first error message while being still able to write
to stderr!
I think this provides a clean enough way of handling requires and conflicts
within modules!
>
> Cheers,
>
> - Leo
>
Ciao
Roberto
--
E-Mail: Rob...@ge... Mail-Address: INFN - Sez. di Genova
Phone: +39 10 353-6301 Via Dodecaneso, 33
Fax: +39 10 353-6319 I-16146 GENOVA
|