[Templates] redirect the fatal error to browser

C. Chad Wallace cwallace@thelodgingco.com
Thu, 25 May 2006 13:19:41 -0700


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Darren Chamberlain wrote:
> * Ken Perl <kenperl at gmail.com> [2006/05/25 14:45]:
>> When some syntax errors in the template html file, I can't see
>> what's happened. If I go to the command line the to re-create the
>> problem then I can see the error like this,
>>
>> file error - parse error - search.xhtml line 71: unexpected end of directive
>>  [% FOREACH d = [ '1','2','three' %]
>> so I know a ']' is missed, for other errors I may use CGI::Carp
>> qw(fatalsToBrowser); to catch the error and see it from the browser.
>> My question is how can I catch template error like above to browser?
> 
> Errors are not handled by TT, you need to do that in your front end.
> tpage does that for you, which is why you see the error on the command
> line.  In your CGI script, you need to do something like:
> 
>   $tt->process(...) || die $tt->error;
> 
> If you are using CGI::Carp, the die will get caught and displayed like
> you want.

Wow, you're right!  What I said was just flat wrong.  I just took
another look at my code, and it does indeed call die:

my $body = '';
unless( $tt->process( 'uploader.html', $tt_vars, \$body ) )
{
	die "Error with Template: ", $tt->error;
}

In my defense, I must say that I've been using this piece of code,
unmodified, for over a year in every TT script that I've written so
far--so you can understand how I took it for granted.

Sorry for the misinformation!
- --

C. Chad Wallace, B.Sc.
The Lodging Company
http://skihills.com/
OpenPGP Public Key ID: 0x262208A0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEdhFcKeSNHCYiCKARAlH5AJ9rnKKhINh02gG4B7EbTTgSN851iwCgx9z4
U+9S0bdeDTnFtlp7h3lWi5c=
=qZz4
-----END PGP SIGNATURE-----