changeset 200:b7d0ddf3df33

Improve logging
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 24 Mar 2011 16:49:32 +0300
parents ce19924b4a7a
children 3819be43aa8d
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java
diffstat 1 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Fri Mar 11 15:34:46 2011 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Thu Mar 24 16:49:32 2011 +0300
@@ -22,6 +22,7 @@
 import jetbrains.buildServer.util.StringUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.Collections;
 import java.util.Set;
@@ -40,17 +41,42 @@
   }
 
   public static void commandFailed(final String cmdName, final ExecResult res) throws VcsException {
-    Throwable exception = res.getException();
     String stderr = res.getStderr();
     String stdout = res.getStdout();
+    String exceptionMessage = getExceptionMessage(res);
     final String message = "'" + cmdName + "' command failed.\n" +
             (!StringUtil.isEmpty(stderr) ? "stderr: " + stderr + "\n" : "") +
             (!StringUtil.isEmpty(stdout) ? "stdout: " + stdout + "\n" : "") +
-            (exception != null ? "exception: " + exception.getLocalizedMessage() : "");
+            (exceptionMessage != null ? "exception: " + exceptionMessage : "");
     Loggers.VCS.warn(message);
+    if (hasImportantException(res)) {
+      Loggers.VCS.error("Error during executing '" + cmdName + "'", res.getException());
+    }
     throw new VcsException(message);
   }
 
+  @Nullable
+  private static String getExceptionMessage(ExecResult result) {
+    Throwable exception = result.getException();
+    String message = null;
+    if (exception != null) {
+      message = exception.getMessage();
+      if (message == null) {
+        message = exception.getClass().getName();
+      }
+    }
+    return message;
+  }
+
+  private static boolean hasImportantException(ExecResult result) {
+    Throwable exception = result.getException();
+    if (exception != null) {
+      return exception instanceof NullPointerException;
+    } else {
+      return false;
+    }
+  }
+
   public static ExecResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
     return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, Collections.<String>emptySet());
   }