mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-12-26 00:31:07 -06:00
minor cleanup on error handling output
This commit is contained in:
parent
ac22b3b395
commit
be74656211
@ -18,6 +18,7 @@ import io.nosqlbench.engine.core.script.MetricsMapper;
|
||||
import io.nosqlbench.engine.core.script.Scenario;
|
||||
import io.nosqlbench.engine.core.script.ScenariosExecutor;
|
||||
import io.nosqlbench.nb.api.markdown.exporter.MarkdownExporter;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.userlibs.apps.VirtDataMainApp;
|
||||
import io.nosqlbench.docsys.core.DocServerApp;
|
||||
import org.slf4j.Logger;
|
||||
@ -51,14 +52,12 @@ public class NBCLI {
|
||||
NBCLI cli = new NBCLI("eb");
|
||||
cli.run(args);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof BasicError) {
|
||||
// System.out.println("ERROR: " + e.getMessage());
|
||||
// System.out.flush();
|
||||
logger.error("ERROR: " + e.getMessage());
|
||||
System.exit(2);
|
||||
} else {
|
||||
throw e;
|
||||
String error = ScenarioErrorHandler.handle(e,true);
|
||||
if (error!=null) {
|
||||
System.out.println(error);
|
||||
}
|
||||
System.out.flush();
|
||||
System.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,12 +284,12 @@ public class NBCLI {
|
||||
|
||||
// Execute Scenario!
|
||||
|
||||
Level clevel = options.wantsConsoleLogLevel();
|
||||
Level llevel = Level.toLevel(options.getLogsLevel());
|
||||
if (llevel.toInt() > clevel.toInt()) {
|
||||
Level consoleLogLevel = options.wantsConsoleLogLevel();
|
||||
Level scenarioLogLevel = Level.toLevel(options.getLogsLevel());
|
||||
if (scenarioLogLevel.toInt() > consoleLogLevel.toInt()) {
|
||||
logger.info("raising scenario logging level to accommodate console logging level");
|
||||
}
|
||||
Level maxLevel = Level.toLevel(Math.min(clevel.toInt(), llevel.toInt()));
|
||||
Level maxLevel = Level.toLevel(Math.min(consoleLogLevel.toInt(), scenarioLogLevel.toInt()));
|
||||
|
||||
scenario.addScriptText(scriptData);
|
||||
ScriptParams scriptParams = new ScriptParams();
|
||||
@ -320,10 +319,13 @@ public class NBCLI {
|
||||
scenariosResults.reportToLog();
|
||||
ShutdownManager.shutdown();
|
||||
|
||||
logger.info(scenariosResults.getExecutionSummary());
|
||||
|
||||
if (scenariosResults.hasError()) {
|
||||
Exception exception = scenariosResults.getOne().getException().get();
|
||||
// logger.warn(scenariosResults.getExecutionSummary());
|
||||
ScenarioErrorHandler.handle(exception,options.wantsStackTraces());
|
||||
System.out.println(exception.getMessage()); // TODO: make this consistent with ConsoleLogging sequencing
|
||||
System.exit(2);
|
||||
} else {
|
||||
logger.info(scenariosResults.getExecutionSummary());
|
||||
|
@ -28,17 +28,19 @@ public class ScenarioErrorHandler {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ScenarioErrorHandler.class);
|
||||
|
||||
public static void handle(Throwable t, boolean wantsStackTraces) {
|
||||
public static String handle(Throwable t, boolean wantsStackTraces) {
|
||||
if (t instanceof ScriptException) {
|
||||
handleScriptException((ScriptException) t, wantsStackTraces);
|
||||
return handleScriptException((ScriptException) t, wantsStackTraces);
|
||||
} else if (t instanceof BasicError) {
|
||||
handleBasicError((BasicError) t, wantsStackTraces);
|
||||
return handleBasicError((BasicError) t, wantsStackTraces);
|
||||
} else if (t instanceof Exception){
|
||||
handleInternalError((Exception) t, wantsStackTraces);
|
||||
return handleInternalError((Exception) t, wantsStackTraces);
|
||||
} else {
|
||||
throw new RuntimeException("Error in exception handler", t);
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleInternalError(Exception e, boolean wantsStackTraces) {
|
||||
private static String handleInternalError(Exception e, boolean wantsStackTraces) {
|
||||
String prefix = "internal error: ";
|
||||
if (e.getCause()!=null && !e.getCause().getClass().getCanonicalName().contains("io.nosqlbench")) {
|
||||
prefix = "Error from driver or included library: ";
|
||||
@ -50,9 +52,10 @@ public class ScenarioErrorHandler {
|
||||
logger.error(e.getMessage());
|
||||
logger.error("for the full stack trace, run with --show-stacktraces");
|
||||
}
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
private static void handleScriptException(ScriptException e, boolean wantsStackTraces) {
|
||||
private static String handleScriptException(ScriptException e, boolean wantsStackTraces) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof PolyglotException) {
|
||||
Throwable hostException = ((PolyglotException) cause).asHostException();
|
||||
@ -69,15 +72,17 @@ public class ScenarioErrorHandler {
|
||||
logger.error("for the full stack trace, run with --show-stacktraces");
|
||||
}
|
||||
}
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
private static void handleBasicError(BasicError e, boolean wantsStackTraces) {
|
||||
private static String handleBasicError(BasicError e, boolean wantsStackTraces) {
|
||||
if (wantsStackTraces) {
|
||||
logger.error(e.getMessage(),e);
|
||||
} else {
|
||||
logger.error(e.getMessage());
|
||||
logger.error("for the full stack trace, run with --show-stacktraces");
|
||||
}
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,6 +62,16 @@ public class ScenarioResult {
|
||||
return Optional.ofNullable(exception);
|
||||
}
|
||||
|
||||
public void rethrowIfError() {
|
||||
if (exception!=null) {
|
||||
if (exception instanceof RuntimeException) {
|
||||
throw ((RuntimeException) exception);
|
||||
} else {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getIOLog() {
|
||||
return this.iolog;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user