From 1e1ec4b702735e83dc956673816c6c2d8d333596 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Thu, 16 Nov 2017 16:58:07 +0000 Subject: Add eval at top level to log exceptions. --- xmpt | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'xmpt') diff --git a/xmpt b/xmpt index 3d7cb3f..2546092 100755 --- a/xmpt +++ b/xmpt @@ -32,24 +32,28 @@ usage(0) if $help; $| = 1; -local %evalpkg::env = read_env($envpath); -my @plans = load_plans($testplanpath, $templatepath); - -# Ignore SIGPIPE at the top level, since it only matters when reading -# or writing to the subprocess. -local $SIG{PIPE} = sub {}; - -my ($inh, $outh) = (\*STDIN, \*STDOUT); -my $pid; -if (@ARGV) { - $inh = $outh = undef; - $pid = open2($inh, $outh, join(' ', @ARGV)); -} -binmode($inh, ':utf8'); -binmode($outh, ':utf8'); +eval { + local %evalpkg::env = read_env($envpath); + my @plans = load_plans($testplanpath, $templatepath); + + # Ignore SIGPIPE at the top level, since it only matters when + # reading or writing to the subprocess. + local $SIG{PIPE} = sub {}; + + my ($inh, $outh) = (\*STDIN, \*STDOUT); + my $pid; + if (@ARGV) { + $inh = $outh = undef; + $pid = open2($inh, $outh, join(' ', @ARGV)); + } + binmode($inh, ':utf8'); + binmode($outh, ':utf8'); + + eval_in($inh, $outh, @plans); + waitpid($pid, 0) if $pid; -eval_in($inh, $outh, @plans); -waitpid($pid, 0) if $pid; + 1; +} or error($@) and exit 3; # TODO: swap over to Pod::Usage. sub usage { -- cgit v1.2.3