logo

Debugging LotusScript Agents

Writing agents that run over the web is not the easiest of tasks if the agent is anything more than slightly complex.

If you come across an error you'll be lucky if you are even aware of it. The "Agent Done" message is probably the closest clue you'll receive. That is why it is often a good idea to include some kind of error handling in every agent that you intend to run via a browser.

To do this start every agent with the line:

On Error Goto ErrorHandler

Then at the bottom of the Initialise event place the following label and code:

ErrorHandler:
Call PrintErrorMsg("Code - " & Str(Err) & ": " & Error$ + ". (onLine " & Str(Erl) & ").", True)


This then calls a subroutine that "prints" the error message back to the user/designer. The second argument to this routine is a boolean that tells it whether to quit execution or not. This can depend on the severity of the error and lets you call the routine from any point in the code, not just when an error occurs.

Code for this routine is:

Sub PrintErrorMsg(errMsg As String, fatal As Integer)

Print {
<h3>An error has occured in the application.</h3>
<h5>Please report the following message to the system administrator:</h5>
<i>} & errMsg & {</i>
<p />
Click here to return:
<a href="$defaultView?OpenView" target="_self">Return</a>
}

If fatal Then End

End Sub


Note: I usually place PrintErrorMsg in a ScriptLibrary so that all of my agents can share it.

Once you have found that there is indeed an error in your code and you know, roughly, where and what it is, you are probably going to have to find out what's causing it.

The best way to do this is to use lines of code that simply print lines of text at specific locations and see which of these actually gets printed. For example the following code produces an error:

print "i am here<br>"
anInt% = otherInt%
print "i got past line 1<br>"
anInt% = aString$
print "i got past line 2<br>"


This will produce two lines of text, "i am here" and "i got past line 1", followed by an error message about a Type Mismatch (I tried to compare two different types! woops). The result will look something like:

Image

It is obvious from this which line the error has occured on. It also warns the user that things maybe aren't going as planned and to not presume the action was taken.


Feedback

    • avatar
    • Johan Känngård
    • Tue 10 Oct 2000

    Hidden functions in LotusScript

    There is a "hidden" function in LotusScript, Lsi_Info. This contains many interesting statistics, like Lsi_Info(2), which contains the current function in the agent. Great to append to the log when trapping errors with On Error...

    Search notes.net for Lsi_Info...

    Keep up the good work! Your site is getting more interesting every day! :-)

    Johan Känngård

    1. Re: Hidden functions in LotusScript: Lsi_info()

      I was interested to learn about the lsi_info() function recently, but could not seem to find any documentation on it, except for 3 parameters for LS memory. I wrote a small chunk of script (in a web agent) to test the function, as follows:

      For i=0 To 255 Print Cstr(i) & "=" & Lsi_info(i) & "<BR>" Next

      Unfortunately it's almost impossible to speculate on the meaning of each of the variables, so was near useless. I have discovered though (correct me if my guess is wrong):

      lsi_info(2) = The name of the currently executing function lsi_info(6) = The version of LotusScript running (!?) lsi_info(9) = Current language (en for english) lsi_info(12) = The name of the function that called this one

      These I have seen documented on Notes.net: lsi_info(50) = LS memory allocated lsi_info(51) = LS memory allocated from OS lsi_info(52) = LS blocks used

      If anyone has a definitive list of these, please post a copy. Unfortunately, this function is next to useless unless you implement an error handler in every function. Give me C code for error handling any day!

      Brendon.

      Show the rest of this thread

  1. re: debugging LS Agents

    Hi,

    on debugging it helps me a lot to set additional Print-Lines for several variables into an if-function

    If debug = 1 then print var end if

    at the top of the script there is a flag saying:

    dim debug as integer debug = 0

    so normaly no debugging-codes are printed. If you want control you set the top-flag to debug = 1, and all controls are printed!

    Buy

    1. re: debugging LS Agents

      Or, why not use a Logger object:

      (Declarations) Private Const MINIMUM_LOG_LEVEL = "debug"

      (Initialize) Dim logger as Logger Set logger = new Logger() logger.setLevel(MINIMUM_LOG_LEVEL) ... Call logger.logDebug("This is a debug message")

      etc. Please let me know if anyone is interested in the full code, which is very similar to Jakarta Log4j and Java´s new logging API. Could be an article here... ?

  2. error in web agent

    Dear friends

    When i run an agent through web the following error msg what can be the reason

    Error 404

    HTTP Web Server: Lotus Notes Exception - Entry not found in index

    thankx

    Niluki

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Agents"

« Previous Article Next Article »
Complete control when printing HTML from an agent   Conditional WebQuerySave agents

About This Article

Author: Jake Howlett
Category: Agents
Keywords: Debug; Error; debugging;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »