Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions jjava-kernel/src/main/java/org/dflib/jjava/kernel/JavaKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ protected List<String> formatError(Throwable e) {
return formatEvaluationTimeoutException((EvaluationTimeoutException) e);
} else if (e instanceof EvaluationInterruptedException) {
return formatEvaluationInterruptedException((EvaluationInterruptedException) e);
} else if (e instanceof RuntimeException && e.getCause() instanceof EvalException) {
return formatEvalException((EvalException) e.getCause());
} else {
return new ArrayList<>(super.formatError(e));
}
Expand Down Expand Up @@ -180,16 +182,30 @@ private List<String> formatIncompleteSourceException(IncompleteSourceException e
private List<String> formatEvalException(EvalException e) {
List<String> fmt = new ArrayList<>();


String evalExceptionClassName = EvalException.class.getName();
String actualExceptionName = e.getExceptionClassName();
super.formatError(e).stream()
.map(line -> line.replace(evalExceptionClassName, actualExceptionName))
.forEach(fmt::add);
fmt.add(errorStyler.secondary(actualExceptionName + ": " + e.getMessage()));
for (StackTraceElement element : e.getStackTrace()) {
fmt.add(errorStyler.secondary("\tat " + element));
}

formatEvalExceptionCause((EvalException) e.getCause(), fmt);
return fmt;
}

private void formatEvalExceptionCause(EvalException e, List<String> fmt) {
if (e == null) {
return;
}

String actualExceptionName = e.getExceptionClassName();
fmt.add(errorStyler.secondary("Caused by: " + actualExceptionName + ": " + e.getMessage()));
for (StackTraceElement element : e.getStackTrace()) {
fmt.add(errorStyler.secondary("\tat " + element));
}

formatEvalExceptionCause((EvalException) e.getCause(), fmt);
}

private List<String> formatUnresolvedReferenceException(UnresolvedReferenceException e) {
List<String> fmt = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ protected String invoke(Method doitMethod) throws Exception {
return id;
}

private RunException wrapInRunException(Throwable cause) {
if (cause instanceof SPIResolutionException) {
return new ResolutionException(((SPIResolutionException) cause).id(), cause.getStackTrace());
}

UserException ue = new UserException(String.valueOf(cause.getMessage()), cause.getClass().getName(), cause.getStackTrace());
if (cause.getCause() != null) {
ue.initCause(wrapInRunException(cause.getCause()));
}
return ue;
}

private Object doInvoke(String id, Method doitMethod) throws Exception {

Future<Object> task = isNestedCall()
Expand Down Expand Up @@ -160,10 +172,8 @@ private Object doInvoke(String id, Method doitMethod) throws Exception {
}
if (cause == null) {
throw new UserException("null", "Unknown Invocation Exception", e.getStackTrace());
} else if (cause instanceof SPIResolutionException) {
throw new ResolutionException(((SPIResolutionException) cause).id(), cause.getStackTrace());
} else {
throw new UserException(String.valueOf(cause.getMessage()), cause.getClass().getName(), cause.getStackTrace());
throw wrapInRunException(cause);
}
} catch (TimeoutException e) {
String message = String.format("Execution timed out after configured timeout of %d %s.",
Expand Down
Loading