Altering errors to not print a stack trace unless --debug is specified.

This commit is contained in:
Rob Greene 2018-06-10 19:17:19 -05:00
parent 1fd8afefcd
commit d49a604412

View File

@ -9,6 +9,7 @@ import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.Callable;
@ -88,7 +89,7 @@ public class Main implements Callable<Void> {
private boolean allOptimizations;
@Option(names = "--debug", description = "Print debug output.")
private boolean debugFlag;
private static boolean debugFlag;
private PrintStream debug = new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
@ -100,7 +101,21 @@ public class Main implements Callable<Void> {
private File sourceFile;
public static void main(String[] args) throws FileNotFoundException, IOException {
CommandLine.call(new Main(), args);
try {
CommandLine.call(new Main(), args);
} catch (Throwable t) {
if (Main.debugFlag) {
t.printStackTrace(System.err);
} else {
String message = t.getMessage();
while (t != null) {
message = t.getMessage();
t = t.getCause();
}
System.err.printf("Error: %s\n", Optional.ofNullable(message).orElse("An error occurred."));
}
System.exit(1);
}
}
@Override