Skip to content

Commit

Permalink
:load now displays errors (fixes #60)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertlatacz committed Nov 28, 2016
1 parent 8f4d4dd commit 6c03bf5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/javarepl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,4 +166,10 @@ public static Sequence<String> entries(File file) {
}
}
}

public static Consumer<Throwable> throwException() {
return throwable -> {
throw new RuntimeException(throwable);
};
}
}
8 changes: 3 additions & 5 deletions src/javarepl/console/TimingOutConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ private void scheduleInactivityTimeout() {
}

private Callable<Object> exitWithCode(final int code) {
return new Callable<Object>() {
public Object call() throws Exception {
System.exit(code);
return null;
}
return () -> {
System.exit(code);
return null;
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/javarepl/console/commands/LoadSourceFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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()));
Expand Down

0 comments on commit 6c03bf5

Please sign in to comment.