Skip Menu |

This queue is for tickets about the Net-SCP-Expect CPAN distribution.

Report information
The Basics
Id: 18077
Status: resolved
Priority: 0/
Queue: Net-SCP-Expect

People
Owner: RYBSKEJ [...] cpan.org
Requestors: dsteinbrunner [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.12
Fixed in: 0.13



Subject: error_handler not handing timeouts properly
I found that Net::SCP::Expect caused my script to die when a connection timed out even though I had an error_handler set. I looked into the code and found that it needed some patching to work correctly, or at least as I expected it to. I have attached my patch and pasted its contents below: --- Expect.pm 2006-03-09 11:16:59.000000000 -0500 +++ /Library/Perl/5.8.6/Net/SCP/Expect.pm 2006-03-09 11:17:53.000000000 -0500 @@ -188,9 +188,11 @@ my $err = $scp->before() || $scp->match(); if($err){ if($handler){ $handler->($err) } - croak("Problem performing scp: $err"); + else{ croak("Problem performing scp: $err") }; } - croak("scp timed out while trying to connect to $host"); + $err = "scp timed out while trying to connect to $host"; + if($handler){ $handler->($err) } + else{ croak($err) }; } if($verbose){ print $scp->before() }
Subject: Net-SCP-Expect.patch
--- Expect.pm 2006-03-09 11:16:59.000000000 -0500 +++ /Library/Perl/5.8.6/Net/SCP/Expect.pm 2006-03-09 11:17:53.000000000 -0500 @@ -188,9 +188,11 @@ my $err = $scp->before() || $scp->match(); if($err){ if($handler){ $handler->($err) } - croak("Problem performing scp: $err"); + else{ croak("Problem performing scp: $err") }; } - croak("scp timed out while trying to connect to $host"); + $err = "scp timed out while trying to connect to $host"; + if($handler){ $handler->($err) } + else{ croak($err) }; } if($verbose){ print $scp->before() }
From: dsteinbrunner [...] pobox.com
I have since also found that I needed the scp to return right after my error handler was called in the case of a timeout. i have updated my patch to reflect this. --- Expect.pm 2006-03-09 11:16:59.000000000 -0500 +++ /Library/Perl/5.8.6/Net/SCP/Expect.pm 2006-03-09 13:00:38.000000000 -0500 @@ -187,10 +187,12 @@ unless($scp->expect($timeout,-re=>'[Pp]assword.*?:|[Pp]assphrase.*?:')){ my $err = $scp->before() || $scp->match(); if($err){ - if($handler){ $handler->($err) } - croak("Problem performing scp: $err"); + if($handler){ $handler->($err); return; } + else{ croak("Problem performing scp: $err") }; } - croak("scp timed out while trying to connect to $host"); + $err = "scp timed out while trying to connect to $host"; + if($handler){ $handler->($err); return; } + else{ croak($err) }; } if($verbose){ print $scp->before() }
--- Expect.pm 2006-03-09 11:16:59.000000000 -0500 +++ /Library/Perl/5.8.6/Net/SCP/Expect.pm 2006-03-09 13:00:38.000000000 -0500 @@ -187,10 +187,12 @@ unless($scp->expect($timeout,-re=>'[Pp]assword.*?:|[Pp]assphrase.*?:')){ my $err = $scp->before() || $scp->match(); if($err){ - if($handler){ $handler->($err) } - croak("Problem performing scp: $err"); + if($handler){ $handler->($err); return; } + else{ croak("Problem performing scp: $err") }; } - croak("scp timed out while trying to connect to $host"); + $err = "scp timed out while trying to connect to $host"; + if($handler){ $handler->($err); return; } + else{ croak($err) }; } if($verbose){ print $scp->before() }
Error handling has been revised to insure that whenever a error_handler is defined, scp() immediately returns after the handler is called; otherwise, scp() will croak. Also, scp() now catches more scp errors, so error handling should be more robust in general. Changed included in 0.13 release.