aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-03-07 18:02:06 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2017-03-07 18:02:06 +0200
commit991ff90bc8dee27023fd96adeda615f4f37ad0e0 (patch)
tree92073cd0e260ccc96347b0dd3c6a0ba62007b62a
parent25cc6f28c808169f1b91b319b68a1f2757532f25 (diff)
downloadbeam-991ff90bc8dee27023fd96adeda615f4f37ad0e0.tar.gz
beam-991ff90bc8dee27023fd96adeda615f4f37ad0e0.tar.bz2
Catch exceptions in open3
-rw-r--r--lib/App/Beam/Backend.pm4
-rw-r--r--lib/App/Beam/Command.pm20
2 files changed, 16 insertions, 8 deletions
diff --git a/lib/App/Beam/Backend.pm b/lib/App/Beam/Backend.pm
index 525b57d..7d23156 100644
--- a/lib/App/Beam/Backend.pm
+++ b/lib/App/Beam/Backend.pm
@@ -59,7 +59,9 @@ sub logcommand {
return unless defined $ret;
my $comname = $cmd->command_name;
if ($ret) {
- if ($ret == -1) {
+ if ($ret =~ /^open3:/) {
+ $self->logger('err', "failed to run $comname: $ret");
+ } elsif ($ret == -1) {
$self->logger('err', "failed to run $comname");
} elsif ($ret & 127) {
$self->logger('err',
diff --git a/lib/App/Beam/Command.pm b/lib/App/Beam/Command.pm
index 1b6c343..79b8b06 100644
--- a/lib/App/Beam/Command.pm
+++ b/lib/App/Beam/Command.pm
@@ -34,13 +34,19 @@ sub run {
my $err = gensym;
return $self->{status} if exists($self->{status});
-
- my $pid = open3(\*STDIN, $out, $err, @{$self->{argv}});
- waitpid($pid, 0);
- $self->{status} = $?;
- local $/ = undef;
- $self->{channel}[CHAN_STDOUT] = <$out>;
- $self->{channel}[CHAN_STDERR] = <$err>;
+
+ eval {
+ my $pid = open3(\*STDIN, $out, $err, @{$self->{argv}});
+ waitpid($pid, 0);
+ };
+ if ($@) {
+ $self->{status} = $@;
+ } else {
+ $self->{status} = $?;
+ local $/ = undef;
+ $self->{channel}[CHAN_STDOUT] = <$out>;
+ $self->{channel}[CHAN_STDERR] = <$err>;
+ }
return $self->{status};
}

Return to:

Send suggestions and report system problems to the System administrator.