From c88b57a1a6b47c8aa1544e34f572069258e1a2c8 Mon Sep 17 00:00:00 2001 From: janakr Date: Mon, 7 Jun 2021 14:37:48 -0700 Subject: [PATCH] Tolerate an IOException when closing the command log. PiperOrigin-RevId: 378008248 --- .../build/lib/runtime/CommandLogModule.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandLogModule.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandLogModule.java index edbe240a25c66a..404640754016b2 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommandLogModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandLogModule.java @@ -16,7 +16,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Supplier; +import com.google.common.flogger.GoogleLogger; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; +import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.LoggingUtil; import com.google.devtools.build.lib.util.io.OutErr; @@ -28,6 +30,8 @@ /** This module logs complete stdout / stderr output of Bazel to a local file. */ public class CommandLogModule extends BlazeModule { + private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); + private CommandEnvironment env; private OutputStream logOutputStream; @@ -76,13 +80,20 @@ static Path getCommandLogPath(Path outputBase) { @Override public void commandComplete() { + CommandEnvironment localEnv = this.env; this.env = null; if (logOutputStream != null) { try { logOutputStream.flush(); logOutputStream.close(); } catch (IOException e) { - throw new RuntimeException(e); + logger.atWarning().withCause(e).log("I/O exception closing log"); + String msg = "I/O exception closing log: " + e.getMessage(); + if (localEnv != null) { + localEnv.getReporter().handle(Event.error(msg)); + } else { + System.err.println(msg); + } } finally { logOutputStream = null; }