changeset 387:88480a85f888

Some exit codes mean errors
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 16 Feb 2012 20:14:30 +0400
parents 62f273711a49 (diff) 00d13c910f5d (current diff)
children 7db31e2b1f90 85cc92fb5dfa
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java	Thu Feb 16 18:20:28 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java	Thu Feb 16 20:14:30 2012 +0400
@@ -8,9 +8,11 @@
 import org.jetbrains.annotations.Nullable;
 
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
 
 import static com.intellij.openapi.util.text.StringUtil.isEmpty;
+import static java.util.Arrays.asList;
 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandUtil.removePrivateData;
 
 /**
@@ -20,6 +22,14 @@
  */
 public class CommandResult {
 
+  //Mercurial returns -1 in the case of errors (see dispatch.py)
+  //and on some shells (e.g. windows cmd) it is truncated to 255.
+  //A non-zero exit code is not always an error:
+  //http://mercurial.selenic.com/bts/issue186
+  //http://mercurial.selenic.com/bts/issue2189
+  //e.g. pull command in hg 2.1 exits with 1 if no new changes were pulled.
+  private static final Set<Integer> ERROR_EXIT_CODES = setOf(-1, 255);
+
   private final Logger myLogger;
   private final String myCommand;
   private final ExecResult myDelegate;
@@ -86,12 +96,8 @@
   }
 
   private boolean isErrorExitCode() {
-    //A non-zero exit code is not always an error:
-    //http://mercurial.selenic.com/bts/issue186
-    //http://mercurial.selenic.com/bts/issue2189
-    //E.g. pull command in hg 2.1 exits with 1 if no new changes were pulled
     int exitCode = myDelegate.getExitCode();
-    return exitCode == -1 || exitCode == 255;
+    return ERROR_EXIT_CODES.contains(exitCode);
   }
 
   private boolean shouldDetectErrors() {
@@ -166,4 +172,8 @@
       }
     }
   }
+
+  private static Set<Integer> setOf(Integer... ints) {
+    return new HashSet<Integer>(asList(ints));
+  }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java	Thu Feb 16 18:20:28 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java	Thu Feb 16 20:14:30 2012 +0400
@@ -48,7 +48,7 @@
 
   @Test(expectedExceptions = VcsException.class,
         dataProvider = "exitCodesForErrors")
-  public void should_detect_error_when_for_exit_code(int exitCode) throws VcsException {
+  public void should_detect_error_for_exit_code(int exitCode) throws VcsException {
     CommandResult commandResult = commandResultFor(execResult().withExitCode(exitCode));
     commandResult.checkCommandFailed();
   }