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:
Jonathan Shook 2024-10-16 15:09:10 -05:00 committed by GitHub
commit 91efee68f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 16 deletions

View File

@ -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;
}

View File

@ -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 {