From 6c03bf5fe4782c3e28369852a3be95bd7de95a0a Mon Sep 17 00:00:00 2001 From: albertlatacz Date: Mon, 28 Nov 2016 19:00:55 +0000 Subject: [PATCH] :load now displays errors (fixes #60) --- src/javarepl/Utils.java | 7 +++++++ src/javarepl/console/TimingOutConsole.java | 8 +++----- src/javarepl/console/commands/LoadSourceFile.java | 5 ++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/javarepl/Utils.java b/src/javarepl/Utils.java index 9d4324d..a141b8d 100644 --- a/src/javarepl/Utils.java +++ b/src/javarepl/Utils.java @@ -13,6 +13,7 @@ import java.net.ServerSocket; import java.net.URI; import java.net.URL; +import java.util.function.Consumer; import java.util.jar.JarFile; import java.util.jar.JarInputStream; import java.util.jar.Manifest; @@ -165,4 +166,10 @@ public static Sequence entries(File file) { } } } + + public static Consumer throwException() { + return throwable -> { + throw new RuntimeException(throwable); + }; + } } diff --git a/src/javarepl/console/TimingOutConsole.java b/src/javarepl/console/TimingOutConsole.java index 0cb6b44..bceea94 100644 --- a/src/javarepl/console/TimingOutConsole.java +++ b/src/javarepl/console/TimingOutConsole.java @@ -53,11 +53,9 @@ private void scheduleInactivityTimeout() { } private Callable exitWithCode(final int code) { - return new Callable() { - public Object call() throws Exception { - System.exit(code); - return null; - } + return () -> { + System.exit(code); + return null; }; } diff --git a/src/javarepl/console/commands/LoadSourceFile.java b/src/javarepl/console/commands/LoadSourceFile.java index 2f3c350..67e3ef9 100644 --- a/src/javarepl/console/commands/LoadSourceFile.java +++ b/src/javarepl/console/commands/LoadSourceFile.java @@ -9,6 +9,7 @@ import static com.googlecode.totallylazy.Files.asFile; import static com.googlecode.totallylazy.Strings.startsWith; import static java.lang.String.format; +import static javarepl.Utils.throwException; public final class LoadSourceFile extends Command { private static final String COMMAND = ":load"; @@ -26,7 +27,9 @@ public void execute(String expression) { if (!path.isEmpty()) { try { - evaluator.evaluate(Strings.lines(path.map(asFile()).get()).toString("\n")); + evaluator.evaluate(Strings.lines(path.map(asFile()).get()).toString("\n")) + .leftOption() + .forEach(throwException()); logger.success(format("Loaded source file from %s", path.get())); } catch (Exception e) { logger.error(format("Could not load source file from %s.\n %s", path.get(), e.getLocalizedMessage()));