cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Haight <pet...@sapros.com>
Subject [C2] Error handling (using actions?)
Date Thu, 08 Feb 2001 08:18:59 GMT

I have been playing with Cocoon2 for the past couple of days. One of the
things I've been playing with is the esql.xsp sample. I had some problems
getting it to work and for the most part I would look in the logs and there
I could read the error messages I was getting back from the PostgreSQL
driver about such things as permissions and missing tables and what not.

I started to experiment with <esql:error-results> to get the error to occur
on the page instead of just in the logs and quickly realized that when there
was an error I wanted a wholly different page layout. I started by modifying
'simple-page2html.xsl' to check for the presence of an error tag using
<xsl:if> and basically having one page layout if there was an error and
another if there wasn't.

This seemed to me to violate the main idea behind sitemaps so I figured I'd
see what I could do to handle this using the sitemaps. It seems that I could
use <map:handle-errors> and take out the code in 'esql.xsl' which changes
the SQL exception into <esql:error-results> and just let the exception
propigate and cause the system to switch to the error page (this should
probably be the default behaviour, see last paragraph).

Is this the right way to go? What is the current methodology is for handling
this situation in C2?

It occurs to me that you could use actions to dynamically select transforms
using data gathered earlier in the pipeline. This would work much like
<map:select> except it would have access to data that gets generated during
pipeline processing.

Basically what I want is to be able to put something like this in the
sitemap:

<map:match pattern="xsp/*">
  <map:generate type="serverpages" src="docs/samples/xsp/{1}.xsp"/>
  <map:select type="exception">
    <map:when test="catch">
      <map:transform src="stylesheets/system/error2html.xsl"/>
    </map:when>
    <map:otherwise>
      <map:transform src="stylesheets/dynamic-page2html.xsl"/>
    </map:otherwise>
  </map:select>
  <map:serialize/>
</map:match>

It seems to me I could do this with actions. I'm not sure exactly how the
syntax would work out in the sitemap, but it would translate to the above
logic.  I would have to introduce some way to throw an 'exception' from
inside an XSP page. Maybe something like this:

<esql:error-results>
  <xsp:throw>
     <error:message><esql:get-message/></error:message>
     <error:description><esql:get-message/></error:description>
     <error:extra><esql:get-stacktrace/></error:extra>
  </xsp:throw>
</esql:error-results>

I'm not really convinced I want this last bit. In fact, I think that if you
don't put the <esql:error-results> tag in your xsp, it should raise the
exception instead of just continuing on down the pipeline.  I think that
most the time, administrators are going to want to see that error page with
the SQL error so that should be the default. Only in some rare cases are
they going to want to have the error message propigate through the standard
pipeline as if no error occurred.


Mime
View raw message