Subject: | Error handling errors |
handle_error returns a 500 status (internal server error) when the
error isn't file not found. This generally causes a content-free error
page due to the usual microsoft 'feature' of providing a 'helpful'
error page. It also causes errors in the system log.
handle_error should return status 200 even in the error case; the error
template will then display as expected.
This was discovered because thumbnail doesn't trap errors doing the
resize. This makes them hard to track down. Even when you see the
error, it's a mysterious internal error in the graphics library.
In this case, it turned out to be a .JPG file that was corrupted.
We can eval the resize & return a more meaningful error. In fact, in
this particular case, we can return an error image so that the whole
gallery doesn't crash because of a single corrupt file.
Patch attached.
Subject: | pg_error_patch2.diff |
--- /usr/lib/perl5/site_perl/5.8.8/CGI/Application/PhotoGallery.pm~ 2008-03-11 11:23:32.000000000 -0400
+++ /usr/lib/perl5/site_perl/5.8.8/CGI/Application/PhotoGallery.pm 2008-07-20 08:17:23.000000000 -0400
@@ -473,7 +473,24 @@
unless ( $data ) {
my $gfx = $self->gfx_lib;
- $data = $gfx->resize( $path, $size );
+ eval {
+ $data = $gfx->resize( $path, $size );
+ }; if ($@) {
+ my $errstr = $@;
+ my $errimg = __FILE__;
+ $errimg =~ s|.pm$|/nothumb.jpg|;
+ if( -r $errimg ) {
+ eval {
+ $data = $gfx->resize( $errimg, $size );
+ }; if ($@) {
+ return handle_error( $self, "Unable to resize $path; file may be corrupt; error image also corrupt\nError string:$errstr" );
+ }
+ } else {
+ return handle_error( $self, "Unable to resize $path; file may be corrupt; error image also missing\nError string:$errstr\n" );
+ }
+ binmode STDOUT;
+ return $data;
+ }
$cache->set( $key => $data );
}
@@ -675,7 +692,7 @@
$error = 'ERROR: File not found.';
}
else {
- $self->header_props( { -status => '500 Error' } );
+ $self->header_props( { -status => '200 Error' } );
}
my $html = $self->load_tmpl(