7 Web Programming

7.7 Finding Bugs

Since debugging of CGI programs can be quite tedious, here are some hints on how to debug CGI programs.

If the execution of the CGI program produces some run-time error (e.g., access to a non-existing files), the error message should be shown in the web page. Furthermore, messages written to standard error output are collected in the log file of the web script. For instance, if the web script is stored at location cgi-bin/myscript.cgi, the log file is cgi-bin/myscript.cgi.log. Hence, if you want to put some debug output in your web script, you should write it to standard error, e.g.,

hPutStrLn stderr "A log message"

(where hPutStrLn and stderr are defined in the standard library IO).

The use of logic variables as references to input elements in HTML forms ensures that typos in the name of references can be detected by the compiler (e.g., resulting in an “undeclared identifier” error message), in contrast to traditional approaches to CGI programming using plain strings as references. However, if we use the same logic variable for two different input elements, this is not detected by the compiler (which is not worse than traditional approaches where this is also not detected) but results in a run-time error that is not easy to understand due to the implementation of the library HTML.Base in Curry. In this case, the web script might fail with a message like “No value found”. Thus, you should check your source program for these possible errors or add some debug output, as described above, to your script.