mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Merge pull request #2048 from nosqlbench/version-output-on-cli-errors
Store version in NBCLI class and display on some log messages
This commit is contained in:
commit
91efee68f1
@ -76,10 +76,12 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
private static final int EXIT_OK = 0;
|
||||
private static final int EXIT_WARNING = 1;
|
||||
private static final int EXIT_ERROR = 2;
|
||||
private static final String version;
|
||||
|
||||
static {
|
||||
loggerConfig = new NBLoggerConfig();
|
||||
ConfigurationFactory.setConfigurationFactory(NBCLI.loggerConfig);
|
||||
version = new VersionInfo().getVersion();
|
||||
}
|
||||
|
||||
private final String commandName;
|
||||
@ -134,7 +136,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
break;
|
||||
}
|
||||
|
||||
final String error = NBCLIErrorHandler.handle(e, showStackTraces);
|
||||
final String error = NBCLIErrorHandler.handle(e, showStackTraces, NBCLI.version);
|
||||
// Commented for now, as the above handler should do everything needed.
|
||||
if (null != error) System.err.println("Scenario stopped due to error. See logs for details.");
|
||||
System.err.flush();
|
||||
@ -188,7 +190,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
NBCLI.logger.info(() -> "Running NoSQLBench Version " + new VersionInfo().getVersion());
|
||||
NBCLI.logger.info(() -> "Running NoSQLBench Version " + NBCLI.version);
|
||||
NBCLI.logger.info(() -> "command-line: " + String.join(" ", args));
|
||||
NBCLI.logger.info(() -> "client-hardware: " + SystemId.getHostSummary());
|
||||
|
||||
@ -251,7 +253,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
}
|
||||
|
||||
if (options.isWantsVersionShort()) {
|
||||
System.out.println(new VersionInfo().getVersion());
|
||||
System.out.println(NBCLI.version);
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class NBCLIErrorHandler {
|
||||
|
||||
private final static Logger logger = LogManager.getLogger("ERRORHANDLER");
|
||||
|
||||
public static String handle(Throwable t, boolean wantsStackTraces) {
|
||||
public static String handle(Throwable t, boolean wantsStackTraces, String version) {
|
||||
|
||||
if (wantsStackTraces) {
|
||||
StackTraceElement[] st = Thread.currentThread().getStackTrace();
|
||||
@ -59,23 +59,23 @@ public class NBCLIErrorHandler {
|
||||
}
|
||||
if (t instanceof ScriptException) {
|
||||
logger.trace("Handling script exception: " + t);
|
||||
return handleScriptException((ScriptException) t, wantsStackTraces);
|
||||
return handleScriptException((ScriptException) t, wantsStackTraces, version);
|
||||
} else if (t instanceof BasicError) {
|
||||
logger.trace("Handling basic error: " + t);
|
||||
return handleBasicError((BasicError) t, wantsStackTraces);
|
||||
return handleBasicError((BasicError) t, wantsStackTraces, version);
|
||||
} else if (t instanceof Exception) {
|
||||
logger.trace("Handling general exception: " + t);
|
||||
return handleInternalError((Exception) t, wantsStackTraces);
|
||||
return handleInternalError((Exception) t, wantsStackTraces, version);
|
||||
} else {
|
||||
logger.error("Unknown type for error handler: " + t);
|
||||
logger.error("Unknown type for error handler(" + version + "):" + t);
|
||||
throw new RuntimeException("Error in exception handler", t);
|
||||
}
|
||||
}
|
||||
|
||||
private static String handleInternalError(Exception e, boolean wantsStackTraces) {
|
||||
String prefix = "internal error: ";
|
||||
private static String handleInternalError(Exception e, boolean wantsStackTraces, String version) {
|
||||
String prefix = "internal error(" + version + "):";
|
||||
if (e.getCause() != null && !e.getCause().getClass().getCanonicalName().contains("io.nosqlbench")) {
|
||||
prefix = "Error from driver or included library: ";
|
||||
prefix = "Error from driver or included library(" + version + "):";
|
||||
}
|
||||
|
||||
if (wantsStackTraces) {
|
||||
@ -90,18 +90,18 @@ public class NBCLIErrorHandler {
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
private static String handleScriptException(ScriptException e, boolean wantsStackTraces) {
|
||||
private static String handleScriptException(ScriptException e, boolean wantsStackTraces, String version) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof PolyglotException) {
|
||||
Throwable hostException = ((PolyglotException) cause).asHostException();
|
||||
if (hostException instanceof BasicError) {
|
||||
handleBasicError((BasicError) hostException, wantsStackTraces);
|
||||
handleBasicError((BasicError) hostException, wantsStackTraces, version);
|
||||
} else {
|
||||
handle(hostException, wantsStackTraces);
|
||||
handle(hostException, wantsStackTraces, version);
|
||||
}
|
||||
} else {
|
||||
if (wantsStackTraces) {
|
||||
logger.error("Unknown script exception:", e);
|
||||
logger.error("Unknown script exception(" + version + "):", e);
|
||||
} else {
|
||||
logger.error(e.getMessage());
|
||||
logger.error("for the full stack trace, run with --show-stacktraces");
|
||||
@ -110,7 +110,7 @@ public class NBCLIErrorHandler {
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
private static String handleBasicError(BasicError e, boolean wantsStackTraces) {
|
||||
private static String handleBasicError(BasicError e, boolean wantsStackTraces, String version) {
|
||||
if (wantsStackTraces) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user