aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-12-29 13:09:20 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2017-12-29 14:17:45 +0100
commit4d6a2243d4799026ee5351261fd238fde400a8bc (patch)
treeea85f6bdda54ae7519877fbe4ef42ba2761e1380 /src
parent7465b0c71083c5ea1297cbd44f86a84bc00a665b (diff)
downloadsonar-scanner-cli-4d6a2243d4799026ee5351261fd238fde400a8bc.tar.gz
sonar-scanner-cli-4d6a2243d4799026ee5351261fd238fde400a8bc.zip
SQSCANNER-47 Improve error logs when exception is a MessageException
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Main.java2
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/MainTest.java18
2 files changed, 11 insertions, 9 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java
index 7144ec8..fb7496e 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Main.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Main.java
@@ -143,7 +143,7 @@ public class Main {
private static boolean showStackTrace(Throwable e, boolean debug) {
// class not available at compile time (loaded by isolated classloader)
- return debug || !"org.sonar.api.utils.MessageException".equals(e.getClass().getName());
+ return debug && !"org.sonar.api.utils.MessageException".equals(e.getClass().getName());
}
private void suggestDebugMode() {
diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
index 869a183..e7b2e64 100644
--- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
@@ -85,7 +85,7 @@ public class MainTest {
e = new IllegalStateException("Error", e);
doThrow(e).when(runner).execute(any(Map.class));
when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
-
+ when(cli.isDebugEnabled()).thenReturn(true);
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
@@ -99,6 +99,7 @@ public class MainTest {
Exception e = new NullPointerException("NPE");
e = new IllegalStateException("Error", e);
doThrow(e).when(runner).start();
+ when(cli.isDebugEnabled()).thenReturn(true);
when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
Main main = new Main(exit, cli, conf, scannerFactory, logs);
@@ -111,22 +112,23 @@ public class MainTest {
}
@Test
- public void show_error_with_stacktrace() {
- Exception e = createException(false);
+ public void show_error_MessageException() {
+ Exception e = createException(true);
testException(e, false);
- verify(logs).error("Error during SonarQube Scanner execution", e);
+ verify(logs).error("Error during SonarQube Scanner execution");
+ verify(logs).error("Caused by: NPE");
verify(logs).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging.");
}
-
+
@Test
- public void show_error_MessageException() {
+ public void show_error_MessageException_debug() {
Exception e = createException(true);
- testException(e, false);
+ testException(e, true);
verify(logs).error("Error during SonarQube Scanner execution");
+ verify(logs).error("my message");
verify(logs).error("Caused by: NPE");
- verify(logs).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging.");
}
@Test