forked from lix-project/hydra
Merge pull request #768 from knl/improve-handling-of-perl-block-eval-errors
Improve handling of Perl's block eval errors
This commit is contained in:
commit
a1e08d8819
|
@ -74,11 +74,11 @@ sub handleDeclarativeJobsetBuild {
|
||||||
my $declPath = ($build->buildoutputs)[0]->path;
|
my $declPath = ($build->buildoutputs)[0]->path;
|
||||||
my $declText = eval {
|
my $declText = eval {
|
||||||
readNixFile($declPath)
|
readNixFile($declPath)
|
||||||
};
|
} or do {
|
||||||
if ($@) {
|
# If readNixFile errors or returns an undef or an empty string
|
||||||
print STDERR "ERROR: failed to readNixFile $declPath: ", $@, "\n";
|
print STDERR "ERROR: failed to readNixFile $declPath: ", $@, "\n";
|
||||||
die;
|
die;
|
||||||
}
|
};
|
||||||
|
|
||||||
my $declSpec = decode_json($declText);
|
my $declSpec = decode_json($declText);
|
||||||
$db->txn_do(sub {
|
$db->txn_do(sub {
|
||||||
|
@ -88,16 +88,17 @@ sub handleDeclarativeJobsetBuild {
|
||||||
while ((my $jobsetName, my $spec) = each %$declSpec) {
|
while ((my $jobsetName, my $spec) = each %$declSpec) {
|
||||||
eval {
|
eval {
|
||||||
updateDeclarativeJobset($db, $project, $jobsetName, $spec);
|
updateDeclarativeJobset($db, $project, $jobsetName, $spec);
|
||||||
};
|
1;
|
||||||
if ($@) {
|
} or do {
|
||||||
print STDERR "ERROR: failed to process declarative jobset ", $project->name, ":${jobsetName}, ", $@, "\n";
|
print STDERR "ERROR: failed to process declarative jobset ", $project->name, ":${jobsetName}, ", $@, "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
1;
|
||||||
|
} or do {
|
||||||
|
# note the error in the database in the case eval fails for whatever reason
|
||||||
|
$project->jobsets->find({ name => ".jobsets" })->update({ errormsg => $@, errortime => time, fetcherrormsg => undef })
|
||||||
};
|
};
|
||||||
$project->jobsets->find({ name => ".jobsets" })->update({ errormsg => $@, errortime => time, fetcherrormsg => undef })
|
|
||||||
if defined $@;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -356,14 +356,13 @@ sub captureStdoutStderr {
|
||||||
alarm $timeout;
|
alarm $timeout;
|
||||||
IPC::Run::run(\@cmd, \$stdin, \$stdout, \$stderr);
|
IPC::Run::run(\@cmd, \$stdin, \$stdout, \$stderr);
|
||||||
alarm 0;
|
alarm 0;
|
||||||
};
|
1;
|
||||||
|
} or do {
|
||||||
if ($@) {
|
|
||||||
die unless $@ eq "timeout\n"; # propagate unexpected errors
|
die unless $@ eq "timeout\n"; # propagate unexpected errors
|
||||||
return (-1, $stdout, ($stderr // "") . "timeout\n");
|
return (-1, $stdout, ($stderr // "") . "timeout\n");
|
||||||
} else {
|
};
|
||||||
return ($?, $stdout, $stderr);
|
|
||||||
}
|
return ($?, $stdout, $stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -391,16 +390,15 @@ sub run {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alarm 0;
|
alarm 0;
|
||||||
};
|
$res->{status} = $?;
|
||||||
|
chomp $res->{stdout} if $args{chomp} // 0;
|
||||||
|
|
||||||
if ($@) {
|
1;
|
||||||
|
} or do {
|
||||||
die unless $@ eq "timeout\n"; # propagate unexpected errors
|
die unless $@ eq "timeout\n"; # propagate unexpected errors
|
||||||
$res->{status} = -1;
|
$res->{status} = -1;
|
||||||
$res->{stderr} = "timeout\n";
|
$res->{stderr} = "timeout\n";
|
||||||
} else {
|
};
|
||||||
$res->{status} = $?;
|
|
||||||
chomp $res->{stdout} if $args{chomp} // 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,11 @@ sub buildStarted {
|
||||||
or die "build $buildId does not exist\n";
|
or die "build $buildId does not exist\n";
|
||||||
|
|
||||||
foreach my $plugin (@plugins) {
|
foreach my $plugin (@plugins) {
|
||||||
eval { $plugin->buildStarted($build); };
|
eval {
|
||||||
if ($@) {
|
$plugin->buildStarted($build);
|
||||||
print STDERR "$plugin->buildStarted: $@\n";
|
1;
|
||||||
|
} or do {
|
||||||
|
print STDERR "error with $plugin->buildStarted: $@\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,9 +55,11 @@ sub buildFinished {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $plugin (@plugins) {
|
foreach my $plugin (@plugins) {
|
||||||
eval { $plugin->buildFinished($build, [@dependents]); };
|
eval {
|
||||||
if ($@) {
|
$plugin->buildFinished($build, [@dependents]);
|
||||||
print STDERR "$plugin->buildFinished: $@\n";
|
1;
|
||||||
|
} or do {
|
||||||
|
print STDERR "error with $plugin->buildFinished: $@\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,9 +78,11 @@ sub stepFinished {
|
||||||
$logPath = undef if $logPath eq "-";
|
$logPath = undef if $logPath eq "-";
|
||||||
|
|
||||||
foreach my $plugin (@plugins) {
|
foreach my $plugin (@plugins) {
|
||||||
eval { $plugin->stepFinished($step, $logPath); };
|
eval {
|
||||||
if ($@) {
|
$plugin->stepFinished($step, $logPath);
|
||||||
print STDERR "$plugin->stepFinished: $@\n";
|
1;
|
||||||
|
} or do {
|
||||||
|
print STDERR "error with $plugin->stepFinished: $@\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,8 +121,8 @@ while (1) {
|
||||||
} elsif ($channelName eq "step_finished") {
|
} elsif ($channelName eq "step_finished") {
|
||||||
stepFinished(int($payload[0]), int($payload[1]));
|
stepFinished(int($payload[0]), int($payload[1]));
|
||||||
}
|
}
|
||||||
};
|
1;
|
||||||
if ($@) {
|
} or do {
|
||||||
print STDERR "error processing message '$payload' on channel '$channelName': $@\n";
|
print STDERR "error processing message '$payload' on channel '$channelName': $@\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,10 @@ sub sendQueueRunnerStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
eval { sendQueueRunnerStats(); };
|
eval {
|
||||||
if ($@) { warn "$@"; }
|
sendQueueRunnerStats();
|
||||||
|
1;
|
||||||
|
} or do { warn "$@"; }
|
||||||
|
|
||||||
my $meminfo = read_file("/proc/meminfo", err_mode => 'quiet') // "";
|
my $meminfo = read_file("/proc/meminfo", err_mode => 'quiet') // "";
|
||||||
$meminfo =~ m/Dirty:\s*(\d+) kB/;
|
$meminfo =~ m/Dirty:\s*(\d+) kB/;
|
||||||
|
|
Loading…
Reference in a new issue