From 03a5ab2517615d93d071aca18a3900f44b3b7dab Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 15 Mar 2019 14:31:27 +0100 Subject: SQSCANNER-58 Return a different error code for functional errors --- src/main/java/org/sonarsource/scanner/cli/Cli.java | 2 +- src/main/java/org/sonarsource/scanner/cli/Exit.java | 3 ++- src/main/java/org/sonarsource/scanner/cli/Main.java | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/sonarsource') diff --git a/src/main/java/org/sonarsource/scanner/cli/Cli.java b/src/main/java/org/sonarsource/scanner/cli/Cli.java index 66196a7..9ffc5dd 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Cli.java +++ b/src/main/java/org/sonarsource/scanner/cli/Cli.java @@ -135,7 +135,7 @@ class Cli { private void printErrorAndExit(String message) { logger.error(message); printUsage(); - exit.exit(Exit.ERROR); + exit.exit(Exit.INTERNAL_ERROR); } private void printUsage() { diff --git a/src/main/java/org/sonarsource/scanner/cli/Exit.java b/src/main/java/org/sonarsource/scanner/cli/Exit.java index adae579..69e9c28 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Exit.java +++ b/src/main/java/org/sonarsource/scanner/cli/Exit.java @@ -21,7 +21,8 @@ package org.sonarsource.scanner.cli; class Exit { static final int SUCCESS = 0; - static final int ERROR = 1; + static final int INTERNAL_ERROR = 1; + static final int USER_ERROR = 2; void exit(int status) { System.exit(status); diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index e6f913a..3e74b17 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -64,7 +64,7 @@ public class Main { void execute() { Stats stats = new Stats(logger).start(); - int status = Exit.ERROR; + int status = Exit.INTERNAL_ERROR; try { Properties p = conf.properties(); checkSkip(p); @@ -77,6 +77,7 @@ public class Main { } catch (Throwable e) { displayExecutionResult(stats, "FAILURE"); showError("Error during SonarQube Scanner execution", e, cli.isDebugEnabled()); + status = isUserError(e) ? Exit.USER_ERROR : Exit.INTERNAL_ERROR; } finally { exit.exit(status); } @@ -121,7 +122,7 @@ public class Main { } private void showError(String message, Throwable e, boolean debug) { - if (showStackTrace(e, debug)) { + if (debug && !isUserError(e)) { logger.error(message, e); } else { logger.error(message); @@ -141,9 +142,9 @@ public class Main { } } - private static boolean showStackTrace(Throwable e, boolean debug) { + private static boolean isUserError(Throwable e) { // class not available at compile time (loaded by isolated classloader) - return debug && !"org.sonar.api.utils.MessageException".equals(e.getClass().getName()); + return "org.sonar.api.utils.MessageException".equals(e.getClass().getName()); } private void suggestDebugMode() { -- cgit v1.2.3