You are here: Message Personalization and Scripting > Advanced Mail Merge and Tcl Scripting > Error Handling and Debugging Scripts

Error Handling and Debugging

 

Tcl scripting in email messages is much different from programming in standard programming environments; normally when you make a mistake programming, that mistake isn't emailed to all of your customers! For this reason, there are some special debugging features built into ListManager. Even with these debugging features, it is recommended that you test your Tcl scripts with a test list.

 

errormode

One of the most useful debugging features is the errormode procedure. The most common form of this procedure is:

 

%%init ; errormode notify your@emailaddr.ess%%

 

As described in the previous section, the init part of this script indicates that this script should only be evaluated once at the beginning of the message send and should always return an empty string.

 

The errormode procedure tells the Tcl processor to abort the message send when an error occurs and to send an error notification to the specified email address. To see where this might be useful, consider the following message text:

 

%%init ; errormode notify your@emailaddr.ess%%

Dear %%merge members_.FullName_%%,
...

 

In this case, the argument to merge has an error in the table name. In a normal message send, this would generate an error but the message would still continue to be send and other scripts processed. The result of a script with an error is normally an empty string. However, since the errormode procedure was used to set a notification address, the Tcl processor will stop processing this message and send a notification to the specified email address. This notification includes an error string that indicates what the error was and includes a copy of the script in which the error occurred.

 

Other error modes are documented in the section ListManager Tcl Procedures.

 

redirect

Another useful debugging feature is the redirect procedure. The argument to redirect is an email address which will always override the email address of the actual recipients. This means that you can send to your list as normal and have all of the messages go to the address you specified and not the list. For example:

 

%%
init ;
errormode notify your@emailaddr.ess ;
redirect your@emailaddr.ess ;
%%

 

This is useful for determining whether scripts execute properly for each member and whether the fields you expect to have data actually do. The problem with this feature is that if you are sending to a big list, you will get a lot of mail. You can use redirect as-is for small test lists, but for large production lists, it is best used in conjunction with the skip procedure.

 

skip

The skip procedure tells ListManager not to send to the current recipient. Along with some simple mathematics and some other Tcl procedures, you can have ListManager only send to every 1000th recipient. For example:

 

%%
init ;
errormode notify your@emailaddr.ess ;
redirect your@emailaddr.ess ;
%%

%%if { [recipindex] % 1000 != 0 } { skip }%%

 

This form of testing is only recommended for advanced users. Most users should only test their scripts on test lists.