changeset 583:81b23a900379 Faradi-7.1.x

Do not include command output in exception message, it could be huge
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 05 Apr 2013 10:56:55 +0400
parents 81fa236998d4
children
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, 15 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java	Thu Jan 10 21:15:25 2013 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java	Fri Apr 05 10:56:55 2013 +0400
@@ -4,7 +4,6 @@
 import com.intellij.openapi.diagnostic.Logger;
 import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.exception.*;
-import jetbrains.buildServer.util.StringUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -146,25 +145,7 @@
   }
 
   private String createCommandLogMessage() {
-    String stderr = getStderr();
-    String stdout = getStdout();
-    String exceptionMessage = getExceptionMessage();
-    return "'" + getCommand() + "' command failed.\n" +
-            (!StringUtil.isEmpty(stdout) ? "stdout: " + stdout + "\n" : "") +
-            (!StringUtil.isEmpty(stderr) ? "stderr: " + stderr + "\n" : "") +
-            (exceptionMessage != null ? "exception: " + exceptionMessage : "");
-  }
-
-  @Nullable
-  private String getExceptionMessage() {
-    //noinspection ThrowableResultOfMethodCallIgnored
-    Throwable exception = getException();
-    if (exception == null)
-      return null;
-    String message = exception.getMessage();
-    if (message == null)
-      message = exception.getClass().getName();
-    return message;
+    return "'" + getCommand() + "' command failed.";
   }
 
   private void rethrowDetectedError() throws VcsException {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java	Thu Jan 10 21:15:25 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java	Fri Apr 05 10:56:55 2013 +0400
@@ -19,6 +19,9 @@
 import java.util.HashSet;
 import java.util.List;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
 import static org.testng.AssertJUnit.*;
 
 /**
@@ -86,6 +89,17 @@
     commandResult.checkCommandFailed();
   }
 
+  public void exception_should_not_contain_command_stdout_or_stderr() {
+    final String stdout = "300Mb of output";
+    final String stderr = "300Mb from stderr";
+    CommandResult cr = commandResultFor(execResult().withStdout(stdout).withStderr(stderr));
+    try {
+      cr.checkCommandFailed();
+    } catch (VcsException e) {
+      assertThat(e.getMessage(), not(containsString(stdout)));
+      assertThat(e.getMessage(), not(containsString(stderr)));
+    }
+  }
 
   ExecResultBuilder execResult() {
     return new ExecResultBuilder();