Skip to content

Commit

Permalink
0002332: Better logging for bsh load filter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jun 25, 2015
1 parent 6f2d047 commit f68d3b0
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import bsh.EvalError;
import bsh.Interpreter;
import bsh.ParseException;
import bsh.TargetError;

public class BshDatabaseWriterFilter extends DynamicDatabaseWriterFilter {
Expand Down Expand Up @@ -112,12 +113,33 @@ protected void executeScripts(DataContext context, String key, Set<String> scrip
}
}
} catch (EvalError e) {
String errorMsg = String.format("Beanshell script %s with error %s", new Object[] {
currentScript, e.getErrorText() });
log.error(errorMsg);
if (isFailOnError) {
throw new SymmetricException(errorMsg);
if (e instanceof ParseException) {
String errorMsg = String
.format("Evaluation error while parsing the following beanshell script:\n\n%s\n\nThe error was on line %d and the error message was: %s",
currentScript, e.getErrorLineNumber(), e.getMessage());
log.error(errorMsg, e);
if (isFailOnError) {
throw new SymmetricException(errorMsg);
}

} else if (e instanceof TargetError) {
Throwable target = ((TargetError) e).getTarget();
String errorMsg = String
.format("Evaluation error occured in the following beanshell script:\n\n%s\n\nThe error was on line %d",
currentScript, e.getErrorLineNumber());
log.error(errorMsg, target);

if (isFailOnError) {
if (target instanceof RuntimeException) {
throw (RuntimeException) target;
} else {
throw new SymmetricException(target);
}
} else {
log.error("Failed while evaluating script", target);
}
}

}
}

Expand Down Expand Up @@ -164,6 +186,8 @@ protected void bind(Interpreter interpreter, DataContext context, Table table, C
interpreter.set(OLD_ + columnName.toUpperCase(), sourceValues.get(columnName));
}
}



}

Expand Down

0 comments on commit f68d3b0

Please sign in to comment.