diff options
author | Kristina Chodorow <kchodorow@google.com> | 2017-03-16 18:26:10 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2017-03-17 12:26:08 +0000 |
commit | f09bd07c89efd64c05f11cb79d8b70eb22b8fd67 (patch) | |
tree | 63d6de0a1d8bc6c48b039a311f0f9576f761cd3d /src/main/java | |
parent | f405ebfb116423670388fd1d02aade823aadd62a (diff) |
Display an error message when there is a status command error
This was printing, fairly unhelpfully `ERROR: Process exited with status 127.` when the .sh file did not exist.
--
PiperOrigin-RevId: 150344684
MOS_MIGRATED_REVID=150344684
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java index 58eab6db22..6b62f2bd06 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel; import static com.google.common.base.StandardSystemProperty.USER_NAME; +import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.base.Function; import com.google.common.base.Joiner; @@ -43,6 +44,7 @@ import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.GotOptionsEvent; import com.google.devtools.build.lib.runtime.WorkspaceBuilder; +import com.google.devtools.build.lib.shell.BadExitStatusException; import com.google.devtools.build.lib.shell.CommandException; import com.google.devtools.build.lib.shell.CommandResult; import com.google.devtools.build.lib.util.CommandBuilder; @@ -120,11 +122,23 @@ public class BazelWorkspaceStatusModule extends BlazeModule { + options.workspaceStatusCommand)); CommandResult result = this.getWorkspaceStatusCommand.execute(); if (result.getTerminationStatus().success()) { - return new String(result.getStdout()); + return new String(result.getStdout(), UTF_8); } - throw new ActionExecutionException( - "workspace status command failed: " + result.getTerminationStatus(), this, true); + throw new BadExitStatusException( + this.getWorkspaceStatusCommand, + result, + "workspace status command failed: " + result.getTerminationStatus()); } + } catch (BadExitStatusException e) { + String errorMessage = e.getMessage(); + try { + actionExecutionContext.getFileOutErr().getOutputStream().write( + e.getResult().getStdout()); + actionExecutionContext.getFileOutErr().getErrorStream().write(e.getResult().getStderr()); + } catch (IOException e2) { + errorMessage = errorMessage + " and could not get stdout/stderr: " + e2.getMessage(); + } + throw new ActionExecutionException(errorMessage, e, this, true); } catch (CommandException e) { throw new ActionExecutionException(e, this, true); } |