[SCM] Debian package checker branch, master, updated. 2.0.0-29-gac85d00
The following commit has been merged in the master branch:
commit e11275d03869a4373c3cae8c7f951a84287581a6
Author: Frank Lichtenheld <djpig@debian.org>
Date: Fri Oct 17 00:19:44 2008 +0200
Lintian::Command::spawn: Improve error handling
Define error handling with the opts->{fail} key. Possible values
are 'never', 'exception', 'error'.
diff --git a/lib/Lintian/Command.pm b/lib/Lintian/Command.pm
index 6fb2071..bc97b5d 100644
--- a/lib/Lintian/Command.pm
+++ b/lib/Lintian/Command.pm
@@ -108,6 +108,15 @@ Use a pipe for STDERR and start the process in the background.
You will need to call $opts->{harness}->finish in order for the started
process to end properly.
+=item fail
+
+Configures the behaviour in case of errors. The default is 'exception',
+which will cause spawn() to die in case of exceptions thrown by IPC::Run.
+If set to 'error' instead, it will also die if the command exits
+with a non-zero error code. If exceptions should be handled by the caller,
+setting it to 'never' will cause it to store the exception in the
+C<exception> key instead.
+
=back
The following additional keys will be set during the execution of spawn():
@@ -122,8 +131,9 @@ full_results()) and to wait for processes started in the background.
=item exception
-If an exception is raised during the execution of the commands, it
-will be catched and stored under this key.
+If an exception is raised during the execution of the commands,
+and if C<fail> is set to 'never', the exception will be catched and
+stored under this key.
=item success
@@ -136,13 +146,12 @@ Will contain the return value of spawn().
sub spawn {
my ($opts, @cmds) = @_;
- my $fail_on_error;
if (ref($opts) ne 'HASH') {
$opts = {};
- $fail_on_error = 1;
}
+ $opts->{fail} ||= 'exception';
- my ($out, $err, $pipe);
+ my ($out, $pipe);
my (@out, @in, @err);
if ($opts->{pipe_in}) {
@in = ('<pipe', $opts->{pipe_in});
@@ -184,9 +193,22 @@ sub spawn {
};
if ($@) {
require Util;
- Util::fail($@) if $fail_on_error;
+ Util::fail($@) if $opts->{fail} ne 'never';
$opts->{success} = 0;
$opts->{exception} = $@;
+ } elsif ($opts->{fail} eq 'error'
+ and !$opts->{success}) {
+ require Util;
+ if ($opts->{description}) {
+ Util::fail("$opts->{description} failed with error code ".
+ $opts->{harness}->result);
+ } elsif (@cmds == 1) {
+ Util::fail("$cmds[0][0] failed with error code ".
+ $opts->{harness}->result);
+ } else {
+ Util::fail("command failed with error code ".
+ $opts->{harness}->result);
+ }
}
# print STDERR Dumper($opts, \@cmds);
return $opts->{success};
diff --git a/lib/Util.pm b/lib/Util.pm
index fd5d4f9..aa29c76 100644
--- a/lib/Util.pm
+++ b/lib/Util.pm
@@ -273,9 +273,8 @@ sub copy_dir {
sub gunzip_file {
my ($in, $out) = @_;
- spawn({out => $out},
- ['gzip', '-dc', $in])
- or fail("error in gzip");
+ spawn({out => $out, fail => 'error'},
+ ['gzip', '-dc', $in]);
}
# create an empty file
--
Debian package checker
Reply to: