Skip Menu |

This queue is for tickets about the Error CPAN distribution.

Report information
The Basics
Id: 3291
Status: resolved
Priority: 0/
Queue: Error

People
Owner: Nobody in particular
Requestors: TJENNESS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Trampling of $@ with deeply nested try blocks
In Error v0.15 (and presumably older versions) sometimes exception information is lost when very many nested try blocks are used and a non-object exception is thrown (eg from a syntax error or die rather than a throw). We are hitting this in our application of 50,000 lines of perl code. Object throws always work fine, the problem is with $@ being cleared as the stack unrolls and so the error message is simply thrown as " at line 273" without any associated text (the class knows there was an error but does not have any string). The attached patch localizes $@ before the try{}, and this fixes the problem. Reproducable with perl 5.6.1 and perl5.8.1RC4 (linux rh7.3). I am as yet unable to reproduce this with a small amount of test code (I am working on that). Tim
--- Error.pm.ori Tue Aug 19 15:59:37 2003 +++ Error.pm Tue Aug 19 16:00:00 2003 @@ -367,6 +367,7 @@ do { local $Error::THROWN = undef; + local $@ = undef; $ok = eval { if($wantarray) {
From: tjenness [...] cpan.org
[TJENNESS - Tue Aug 19 22:10:06 2003]: Show quoted text
> In Error v0.15 (and presumably older versions) sometimes exception > information is lost when very many nested try blocks are used and a > non-object exception is thrown (eg from a syntax error or die > rather than a throw). We are hitting this in our application of > 50,000 lines of perl code. Object throws always work fine, the > problem is with $@ being cleared as the stack unrolls and so the > error message is simply thrown as " at line 273" without any > associated text (the class knows there was an error but does not > have any string). The attached patch localizes $@ before the try{}, > and this fixes the problem.
Sleeping on it, the problem is obvious, if an object destructor itself includes a try block then that $@ will trample all over the $@ set from the main try block ($@ is set, then the block exits and variables created in that block go out of scope, the destructor then does a try which sets $@ (usually to '' if the try block is okay) and then Error reports that there was an error but the value of the error is ''. Show quoted text
> > Reproducable with perl 5.6.1 and perl5.8.1RC4 (linux rh7.3). I am as > yet unable to reproduce this with a small amount of test code (I am > working on that).
Code attached that reproduces the bug. With the patch attached to the initial bug report this code works as expected. Tim
use Data::Dumper; use Error qw/ :try /; my $E; try { my $y = ErrorTest->new(); # throw Error::Simple("Object die"); die "throw normal die"; } catch Error with { $E = shift; print "Error object clause\n"; } otherwise { $E = shift; print "Otherwise clause\n"; }; print "Exception\n" . Dumper($E)."\n";; $E->throw if $E; exit; package ErrorTest; use Error qw/ :try /; sub new { return bless {}, 'ErrorTest'; } sub DESTROY { my $self = shift; print "In destructor"; try { 1; } otherwise { }; return; }
Subject: Re: [rt.cpan.org #3291] Resolved: Trampling of $@ with deeply nested try blocks
Date: Fri, 7 Apr 2006 09:47:11 -1000 (HST)
To: Shlomi Fish via RT <bug-Error [...] rt.cpan.org>
From: Tim Jenness <t.jenness [...] jach.hawaii.edu>
Was the patch actually applied though? The new CPAN version does not have it. On Fri, 7 Apr 2006, Shlomi Fish via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=3291 > > > According to our records, your request has been resolved. If you have any > further questions or concerns, please respond to this message. >
-- Tim Jenness JAC software http://www.jach.hawaii.edu/~timj
On Fri Apr 07 15:47:37 2006, t.jenness@jach.hawaii.edu wrote: Show quoted text
> > Was the patch actually applied though? The new CPAN version does not
have Show quoted text
> it. >
Wait for Error-0.15007, which was uploaded to CPAN a few minutes ago. It will take some time for it to arrive. Regards, Shlomi Fish Show quoted text
> On Fri, 7 Apr 2006, Shlomi Fish via RT wrote: >
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=3291 > > > > > According to our records, your request has been resolved. If you
have any Show quoted text
> > further questions or concerns, please respond to this message. > >
>