Forum OpenACS Q&A: Debugging in OpenACS

Collapse
Posted by James Darwin on
hi...
What would be the most efficient way to debug tcl files? I want to
have some 'print statements' and write the values of variables out
to something. What about 'puts'???
Collapse
Posted by James Darwin on
Also, would there be a difference in debugging the tcl files in the
www folder compared to debugging tcl files in tcl folder?
Collapse
Posted by Ayman M on
Hi James,

I was told by some other members in OpenACS that you could do the following:

ns_log notice "UNIQUESTRING: The print statement and $variable"

then to view the output you could do something like:

cat /usr/local/aolserver/yourserver-error.log | grep UNIQUESTRING

You could also use 'less'.

Im new to all of this so it is probably not the best way of doing it but it might help you for the meantime.

Hope that helps,
Ayman.
Collapse
Posted by Tilmann Singer on
Changes to the tcl files in the www/ folder will be considered automatically when reloading the page, whereas you have to explicitely mark the tcl files in the tcl/ folder as "watched" when you want your changes to take effect without a server restart. To mark files as watched go to /acs-admin/apm - if you have already modified some files then this page will offer to reload the affected package and after that to mark the changed files as watched. Otherwise you can go to the package via the package list and mark the files as watched that you plan to change. The same needs to be done for *.xql files (also below www/) if you are using them.

To debug you can also do

tail -f /usr/local/aolserver/yourserver-error.log | grep UNIQUESTRING
Collapse
Posted by defunct defunct on
If you're super ambitious you could use TclPro. To be honest I've *never* come across anything that warranted a full debugger for TCL.. But its there and workable.
Collapse
Posted by Jonathan Ellis on
another thing you can do with "debugging tcl files in tcl folder" is telnet to your nscp port.  then you can invoke library functions w/o having to go through a www page to do it.
Collapse
Posted by Kevin Crosbie on
I wrote this proc to do my debugging:

ad_proc -public log_tcl_error {
{-errmsg {}}
{-param_list {}}
} {

	set msg "
------------- Error in proc: [lindex [info level -1] 0] -------------
"
	append msg "Error message follows:
"
	append msg "$errmsg
"
	if { [llength $param_list] > 0 } {
		append msg "
Parameters:
"
		foreach param $param_list {
			upvar 1 $param varname
			# Handle arrays
			if { [array exists varname] } {
				append msg "(Array) $param = [array get varname]
"
			}	elseif { [info exists varname] } {
				append msg "$param = $varname
"
			} else {
				append msg "$param didn't exist
"
			}
		}
	}
	append msg "----------------------------------------------------------------------"

	ns_log Error $msg

}

You can call this in your code by doing:
log_tcl_error -errmsg $errmsg -param_list {param_name_1 param_name_2}

where errmsg is a string and param_name_1 and param_name_2 are the names of variables you want to print out.
Note, param can be an array, list, string.   It can't be an ns_set or a multirow.
This is best used in db_transaction on_error blocks and in catch blocks where an error message is available.

This proc will print the following to the error log:

------------- Error in proc: a_proc_in_my_tcl_folder -------------
Error message follows:
ora8.c:3930:ora_tcl_command: error in `OCIStmtExecute ()': ORA-01747: invalid user.table.column, table.column, or column specification

SQL: 
				update a_table 
				set a_col = :col_val,
			 !>>>!where pk_id = :myid 
			

Parameters:
param_1 = 123
param_2 = 456
----------------------------------------------------------------------

When debugging, just run:
tail -f /apps/aol33/log/my-server-error.log | grep -A 15 "------------- Error"

This will print out 15 lines every time it sees an error.

Hope this helps.
Collapse
Posted by Kevin Crosbie on
Of course I forgot to escape the \n's, so an line with " on its own should be \n" at the end of the previous line