Skip to content

Commit

Permalink
Tolerate an IOException when closing the command log.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 378008248
  • Loading branch information
janakdr authored and copybara-github committed Jun 7, 2021
1 parent 7d3bdbc commit c88b57a
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c88b57a

Please sign in to comment.