1

I'm suffering an annoying problem when trying to die from within an eval.

The code is as follows;

$status = eval { $self->$func( @{$y->{args}} ); };

in this case $self->$func points to a handler that detaches to a certain page on error like this:

sub detach
{
    my $self   = shift;
    my $url    = shift;
    my @params = @_;

    if( $url !~ /^\// )
    {
        $url = '/' . $self->namespace . '/' . $url;
    }
    $url =~ s/\sat.*$//;
    print STDERR $self->uri . ": Detaching to " . $url . "\n";

    die "REDIR:$url";
}

this should place "REDIR:$url" into $@ so it's available when the eval exits.

However, instead Carp.pm dies, I assume somewhere in the internals of die with

Bizarre copy of ARRAY in sassign at /usr/share/perl/5.10/Carp.pm line 182

Looking around there is some suggestion that there is a bug deep in perl relating to the stack during die (e.g. http://code.activestate.com/lists/perl5-porters/149248/), however I'm afraid that at this point I'm at the limit of my knowledge of perl and I'm not sure if this is relevant, or what to do about it if it is. :(

Does anyone know if there is a way around this problem or another way to pass an error string back from the eval, or if I'm reading this incorrectly?

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
mark
  • 1,769
  • 3
  • 19
  • 38
  • can you provide a working example? – perreal Jul 22 '12 at 10:52
  • I've tried putting the code into an example however it works fine, which leads me to think it's something to do with the article I referenced. At the time I thought I might have an old version of Carp , however that's up to date. I'll keep trying to get a failing example and post it if I have success. – mark Jul 22 '12 at 11:41
  • Try to reproduce the problem with the [current stable version](http://www.perl.org/get.html); if you succeed, [file a bug](http://p3rl.org/bug). Your 5.10 is old and [unsupported](http://perldoc.perl.org/perlpolicy.html#MAINTENANCE-AND-SUPPORT), chances are good this bug has already been fixed meanwhile. – daxim Jul 22 '12 at 17:02
  • Sorry all - I went on holiday. I'll try the latest version and see if that helps. – mark Aug 05 '12 at 19:23

2 Answers2

1

This sounds to me like #52610. Are you using any module that hooks into the debugger that could be the culprit?

Leon Timmermans
  • 30,029
  • 2
  • 61
  • 110
  • No, I'll try updating to the latest perl and report back. – mark Aug 05 '12 at 19:24
  • 1
    Carp hooks into the DB package. Workaround patch [here](http://www.perlmonks.org/index.pl?node_id=969714) (Also is somewhere buried in the link you gave). – runrig Dec 20 '12 at 21:36
1

This turned out to be a problem with the version of Perl I was using. Upgrading to 5.16.1 resolved the problem.

mark
  • 1,769
  • 3
  • 19
  • 38
  • Not really, upgrading just does not trigger the Carp bug anymore. Upgrading to 5.16.1 or newer will not necessarily fix the problem (cf. the other answer by leon at http://stackoverflow.com/a/11603591/1905491). – stefanct Jul 21 '16 at 14:00