in gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsoleErrorHandlerImpl.java [50:110]
private void displayError(final Throwable error) {
assert error != null;
// Decode any error notifications
Throwable cause = error;
if (error instanceof ErrorNotification) {
cause = error.getCause();
}
IO io = ShellContextHolder.get().getIo();
// Spit out the terse reason why we've failed
io.err.print("@|bold,red ERROR| ");
io.err.print(cause.getClass().getSimpleName());
io.err.println(": @|bold,red " + cause.getMessage() + "|");
// Determine if the stack trace flag is set
String stackTraceProperty = System.getProperty("gshell.show.stacktrace");
boolean stackTraceFlag = false;
if (stackTraceProperty != null) {
stackTraceFlag = stackTraceProperty.trim().equals("true");
}
if (io.isDebug()) {
// If we have debug enabled then skip the fancy bits below, and log the full error, don't decode shit
log.debug(error.toString(), error);
}
else if (io.isVerbose() || stackTraceFlag) {
// Render a fancy ansi colored stack trace
StackTraceElement[] trace = cause.getStackTrace();
StringBuilder buff = new StringBuilder();
//
// TODO: Move this to helper in gshell-ansi
//
for (StackTraceElement e : trace) {
buff.append(" @|bold at| ").
append(e.getClassName()).
append(".").
append(e.getMethodName()).
append(" (@|bold ");
buff.append(e.isNativeMethod() ? "Native Method" :
(e.getFileName() != null && e.getLineNumber() != -1 ? e.getFileName() + ":" + e.getLineNumber() :
(e.getFileName() != null ? e.getFileName() : "Unknown Source")));
buff.append("|)");
//
// FIXME: This does not properly display the full exception detail when cause contains nested exceptions
//
io.err.println(buff);
buff.setLength(0);
}
}
io.err.flush();
}