Skip to content

Commit 85cc2b5

Browse files
committed
ScriptREPL: make evaluation errors less verbose
When something goes wrong interpreting a line of code, let's just display the error message, not the whole stack trace, unless we are in debug mode.
1 parent 2536222 commit 85cc2b5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/org/scijava/script/ScriptREPL.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.List;
4343

4444
import javax.script.Bindings;
45+
import javax.script.ScriptException;
4546

4647
import org.scijava.Context;
4748
import org.scijava.Gateway;
@@ -154,7 +155,17 @@ public boolean evaluate(final String line) {
154155
out.println(s(result));
155156
}
156157
}
158+
catch (final ScriptException exc) {
159+
// NB: Something went wrong interpreting the line of code.
160+
// Let's just display the error message, unless we are in debug mode.
161+
if (log.isDebug()) exc.printStackTrace(out);
162+
else {
163+
final String msg = exc.getMessage();
164+
out.println(msg == null ? exc.getClass().getName() : msg);
165+
}
166+
}
157167
catch (final Throwable exc) {
168+
// NB: Something unusual went wrong. Dump the whole exception always.
158169
exc.printStackTrace(out);
159170
}
160171
}

0 commit comments

Comments
 (0)