diff options
author | ulfjack <ulfjack@google.com> | 2017-07-24 10:42:20 +0200 |
---|---|---|
committer | Jakob Buchgraber <buchgr@google.com> | 2017-07-24 13:18:49 +0200 |
commit | fc040ce6eec07e3b2722ba94b504272be5ace202 (patch) | |
tree | a036de458fc51af993efa8e3be9255e369b1a2e4 | |
parent | b8205c89767f5cdcc639d72fe36c243a1742001c (diff) |
SpawnResult: allow signaling catastrophic errors, and compute detail message
PiperOrigin-RevId: 162906926
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/exec/SpawnExecException.java | 31 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/exec/SpawnResult.java | 40 |
2 files changed, 44 insertions, 27 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnExecException.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnExecException.java index bd9f5d8485..5ae4436ad4 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SpawnExecException.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnExecException.java @@ -19,9 +19,7 @@ import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.Spawn; import com.google.devtools.build.lib.exec.SpawnResult.Status; -import com.google.devtools.build.lib.shell.TerminationStatus; import com.google.devtools.build.lib.util.ExitCode; -import java.util.Locale; /** * A specialization of {@link ExecException} that indicates something went wrong when trying to @@ -56,45 +54,24 @@ public class SpawnExecException extends ExecException { @Override public ActionExecutionException toActionExecutionException(String messagePrefix, boolean verboseFailures, Action action) { - TerminationStatus status = new TerminationStatus( - result.exitCode(), result.status() == Status.TIMEOUT); - String reason = " (" + status.toShortString() + ")"; // e.g " (Exit 1)" - String explanation = status.exited() ? "" : ": " + getMessage(); - - if (!result.status().isConsideredUserError()) { - String errorDetail = result.status().name().toLowerCase(Locale.US) - .replace('_', ' '); - explanation += ". Note: Remote connection/protocol failed with: " + errorDetail; - } - if (result.status() == Status.TIMEOUT) { - explanation += - String.format( - " (failed due to timeout after %.2f seconds.)", - result.getWallTimeMillis() / 1000.0f); - } else if (result.status() == Status.OUT_OF_MEMORY) { - explanation += " (Remote action was terminated due to Out of Memory.)"; - } - if (result.status() != Status.TIMEOUT && forciblyRunRemotely) { - explanation += " Action tagged as local was forcibly run remotely and failed - it's " - + "possible that the action simply doesn't work remotely"; - } - if (messagePrefix == null) { messagePrefix = action.describe(); } // Note: we intentionally do not include the ExecException here, unless verboseFailures is true, // because it creates unwieldy and useless messages. If users need more info, they can run with // --verbose_failures. + String message = result.getDetailMessage( + messagePrefix, getMessage(), isCatastrophic(), forciblyRunRemotely); if (verboseFailures) { return new ActionExecutionException( - messagePrefix + " failed" + reason + explanation, + message, this, action, isCatastrophic(), getExitCode()); } else { return new ActionExecutionException( - messagePrefix + " failed" + reason + explanation, + message, action, isCatastrophic(), getExitCode()); diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnResult.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnResult.java index 30e8c8449c..b3a03839d3 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SpawnResult.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnResult.java @@ -16,6 +16,8 @@ package com.google.devtools.build.lib.exec; import com.google.common.base.Preconditions; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; +import com.google.devtools.build.lib.shell.TerminationStatus; +import java.util.Locale; import javax.annotation.Nullable; /** @@ -125,6 +127,8 @@ public interface SpawnResult { */ boolean setupSuccess(); + boolean isCatastrophe(); + /** The status of the attempted Spawn execution. */ Status status(); @@ -146,6 +150,9 @@ public interface SpawnResult { /** Whether the spawn result was a cache hit. */ boolean isCacheHit(); + String getDetailMessage( + String messagePrefix, String message, boolean catastrophe, boolean forciblyRunRemotely); + /** * Basic implementation of {@link SpawnResult}. */ @@ -171,6 +178,11 @@ public interface SpawnResult { } @Override + public boolean isCatastrophe() { + return false; + } + + @Override public int exitCode() { return exitCode; } @@ -194,6 +206,34 @@ public interface SpawnResult { public boolean isCacheHit() { return cacheHit; } + + @Override + public String getDetailMessage( + String messagePrefix, String message, boolean catastrophe, boolean forciblyRunRemotely) { + TerminationStatus status = new TerminationStatus( + exitCode(), status() == Status.TIMEOUT); + String reason = " (" + status.toShortString() + ")"; // e.g " (Exit 1)" + String explanation = status.exited() ? "" : ": " + message; + + if (!status().isConsideredUserError()) { + String errorDetail = status().name().toLowerCase(Locale.US) + .replace('_', ' '); + explanation += ". Note: Remote connection/protocol failed with: " + errorDetail; + } + if (status() == Status.TIMEOUT) { + explanation += + String.format( + " (failed due to timeout after %.2f seconds.)", + getWallTimeMillis() / 1000.0f); + } else if (status() == Status.OUT_OF_MEMORY) { + explanation += " (Remote action was terminated due to Out of Memory.)"; + } + if (status() != Status.TIMEOUT && forciblyRunRemotely) { + explanation += " Action tagged as local was forcibly run remotely and failed - it's " + + "possible that the action simply doesn't work remotely"; + } + return messagePrefix + " failed" + reason + explanation; + } } /** |