Protect logged exec spooling from no output (#42177)

This commit adds a guard around reading the spooled LoggedExec output.
It is possible the exec command did not output anything, and failed,
which would trigger a failure to read the output file.
This commit is contained in:
Ryan Ernst 2019-05-16 15:38:15 -04:00
parent c40bd31073
commit a6e63e6fa8
1 changed files with 4 additions and 1 deletions

View File

@ -63,7 +63,10 @@ public class LoggedExec extends Exec {
out = new LazyFileOutputStream(spoolFile); out = new LazyFileOutputStream(spoolFile);
outputLogger = logger -> { outputLogger = logger -> {
try { try {
Files.lines(spoolFile.toPath()).forEach(logger::error); // the file may not exist if the command never output anything
if (Files.exists(spoolFile.toPath())) {
Files.lines(spoolFile.toPath()).forEach(logger::error);
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("could not log", e); throw new RuntimeException("could not log", e);
} }