Changeset 48

Show
Ignore:
Timestamp:
08/10/09 15:58:56 (5 years ago)
Author:
clinton
Message:

Adding debugging for error handling, and also a queiter error handler

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Mungo.pm

    r46 r48  
    227227  $self = $self->new($r) unless(ref $self); 
    228228  $self->Response()->start(); 
    229   local $SIG{__DIE__} = \&Mungo::MungoDie
     229  local $SIG{__DIE__} = \&Mungo::wrapErrorsInObjects
    230230  eval { 
    231231    $main::Request = $self->Request(); 
     
    255255 
    256256 
    257 sub MungoDie
     257sub wrapErrorsInObjects
    258258  my $i = 0; 
    259259  my @callstack; 
  • trunk/lib/Mungo/Response.pm

    r47 r48  
    7070use HTML::Entities; 
    7171our $AUTOLOAD; 
     72 
     73our $DEBUG = 0; 
     74use Data::Dumper; 
    7275 
    7376my $one_true_buffer = ''; 
     
    227230 
    228231sub Include { 
    229   my $self = shift; 
    230   my $subject = shift; 
    231   my $_r = tied %$self; 
    232   my $rv; 
    233   eval { 
    234     local $SIG{__DIE__} = \&Mungo::MungoDie; 
    235     if(ref $subject) { 
    236       $rv = $_r->{data}->{Mungo}->include_mem($subject, @_); 
    237     } 
    238     else { 
    239       $rv = $_r->{data}->{Mungo}->include_file($subject, @_); 
    240     } 
    241   }; 
    242   if($@) { 
    243     # If we have more than 1 item in the IO stack, we should just re-raise. 
    244     if (scalar(@{$_r->{data}->{'IO_stack'} || []}) > 1) { 
    245       local $SIG{__DIE__} = undef; 
    246       die $@; 
    247     } 
    248     my $hashref = $@; 
     232    my $self = shift; 
     233    my $subject = shift; 
     234    my $_r = tied %$self; 
     235    my $rv; 
    249236    eval { 
    250       if($_r->{data}->{OnError}) { 
    251         $_r->{data}->{OnError}->($self, $hashref, $subject); 
    252       } 
    253       else { 
    254         $self->defaultErrorHandler($hashref, $subject); 
    255      
     237        local $SIG{__DIE__} = \&Mungo::wrapErrorsInObjects; 
     238        if(ref $subject) { 
     239            $rv = $_r->{data}->{Mungo}->include_mem($subject, @_); 
     240        } else { 
     241            $rv = $_r->{data}->{Mungo}->include_file($subject, @_); 
     242       
    256243    }; 
    257244    if($@) { 
    258       # Oh, dear lord this is bad.  We'd died trying to print out death. 
    259       print STDERR "Mungo::Response -> die in error renderer\n"; 
    260       print STDERR $hashref; 
    261       print STDERR $@; 
    262     } 
    263     return undef; 
    264   } 
    265   return $rv; 
     245        if ($DEBUG) { print STDERR __PACKAGE__ . ':' . __LINE__ . "- Have level one error: $@\n"; } 
     246 
     247        # If we have more than 1 item in the IO stack, we should just re-raise. 
     248        if (scalar(@{$_r->{data}->{'IO_stack'} || []}) > 1) { 
     249            local $SIG{__DIE__} = undef; 
     250            if ($DEBUG > 1) { print STDERR __PACKAGE__ . ':' . __LINE__ . "- rethrowing\n"; } 
     251            die $@; 
     252        } 
     253        my $hashref = $@; 
     254        eval { 
     255            if($_r->{data}->{OnError}) { 
     256                if ($DEBUG > 1) { print STDERR __PACKAGE__ . ':' . __LINE__ . "- have custom error handler, calling\n"; } 
     257                $_r->{data}->{OnError}->($self, $hashref, $subject); 
     258            } else { 
     259                if ($DEBUG > 1) { print STDERR __PACKAGE__ . ':' . __LINE__ . "- no custom error handler, using default\n"; } 
     260                $self->defaultErrorHandler($hashref, $subject); 
     261            } 
     262        }; 
     263        if ($@) { 
     264            # Oh, dear lord this is bad.  We'd died trying to print out death. 
     265            print STDERR "Mungo::Response -> die in error renderer\n"; 
     266            print STDERR $hashref; 
     267            print STDERR $@; 
     268        } 
     269        return undef; 
     270    } 
     271    return $rv; 
    266272} 
    267273 
     
    272278  my $subject = shift; 
    273279  my $_r = tied %$self; 
     280  if ($DEBUG > 1) { print STDERR __PACKAGE__ . ':' . __LINE__ . "- in default error handler\n"; } 
     281 
    274282  print "Error in Include($subject):<br />\n"; 
    275283  my $pkg = $href->{callstack}->[0]->[0];