Forum OpenACS Q&A: Suggestion: Wrapper for tclCmd error

Hi all,
what do you think about a wrapper for the tcl command error. From a users perspective simply using

error message info code

is not very usable. The user's first thought is "oh. maybe I broke the system." The log is very cryptical and the design of the message completely different to that of the system.

My suggestion would be to write a simple wrapper for the error command which uses the template system. Thus the error message is displayed inside the master template of the site and you can write some extra stuff for the user as a starting point for orientation...like email, or posting a bug, or link to the documentation...

What do you think?

Greetings,
Nima

Collapse
Posted by Nima Mazloumi on
Or do we have something like this already? Then one maybe can scan the code and replace these calls with the appropriate wrapper. I could do that :)
Collapse
Posted by Joel Aufrecht on
ad_return_complaint, ad_return_error
Collapse
Posted by Nima Mazloumi on
Hi Joel,
you are right. But still these messages are returned not using the master template of the OpenACS installation and have a total different look&feel.

I was rather thinking of something like this:

# /wrapper-procs.tcl
ad_library {
}

namespace eval wrapper {}

ad_proc -public wrapper::ad_return_error { msg content } {
    Wrapper for error messages
} {
    wrap $msg $content
}

ad_proc -public wrapper::ad_return_complaint { msg content } {
    Wrapper for complaints
} {
    wrap $msg $content
}

ad_proc -public wrapper::wrap_content { content } {
    Wrapper for any content
} {
    wrap "" $content
}

ad_proc -public wrap { msg content } {
    Wraps the error message inside a template page if existent and if a placeholdertag is given.
} {
    set message "<h1>$msg</h1><p>$content</p>"
    set templatePath [ad_parameter -package_id [wrapper_instance_id] Template wrapper]
        if { ![empty_string_p $templatePath] } {
            set template [ad_parse_template $templatePath]
            set placeholder [ad_parameter TemplatePlaceHolderTag]
            set placeholder [ad_parameter -package_id [wrapper_instance_id] TemplatePlaceHolderTag wrapper]
            if { ![empty_string_p $placeholder ] } {
                set header ""
                set footer ""
                if {[catch { regexp "^(.*)<$placeholder\[ \n\t\]*/>(.*)$" $template match header footer } err] == 1} {
                    append $content "<hr><b>Wrapper</b>: Regular expression failed.<hr>"
                    ad_return_error $msg $content
                } else {
                    set result ""
                    append result $header $message $footer
                    doc_return 200 text/html $result
                }
            } else {
                append $content "<hr><b>Wrapper ([wrapper_instance_id])</b>: No PlaceHolder parameter set for the template<hr>"
                ad_return_error $msg $content
            }
        } else {
            append $content "<hr><b>Wrapper ([wrapper_instance_id])</b>: Template path error<hr>"
            ad_return_error $msg $content
        }
}

ad_proc -private wrapper_instance_id {} {

    @return The instance of a running wrapper.

} {
    return [util_memoize [list db_string acs_kernel_id_get {
    select package_id from apm_packages
    where package_key = 'wrapper'
    } -default 0]]
}

Now what it does is really simple. I created a package called wrapper (a singleton and auto mounted on /wrapper) which has two parameters Template and TemplatePlaceHolderTag (like the Gatekeeper-Package I sent you).

Once installed the wrapper simply wraps ad_return_complaint and ad_return_error inside the master template.

What do you think?

Greetings,
Nima

Collapse
Posted by Don Baccus on
ad_return_complaint is templated (and calls the subsite master template) as of the 5.1 branch, anyway, not sure if it got snuck into one of the later 5.0's or not.
Collapse
Posted by Nima Mazloumi on
Don, you are right. On dotLRN 2.0.1 this is not the case yet.

Greetings,
Nima