Skip to content

Commit

Permalink
Prevent printing stack trace of ScalacInvoker on known compilation er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
WojciechMazur committed Aug 30, 2024
1 parent 8172568 commit 3f0e5ba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/java/io/bazel/rulesscala/scalac/ScalacInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public static ScalacInvokerResults invokeCompiler(CompileOptions ops, String[] c
comp.process(compilerArgs);
} catch (Throwable ex) {
if (ex.toString().contains("scala.reflect.internal.Types$TypeError")) {
throw new RuntimeException("Build failure with type error", ex);
throw new ScalacWorker.CompilationFailed("with type error", ex);
} else if (ex.toString().contains("java.lang.StackOverflowError")) {
throw new RuntimeException("Build failure with StackOverflowError", ex);
throw new ScalacWorker.CompilationFailed("with StackOverflowError", ex);
} else if (isMacroException(ex)) {
throw new RuntimeException("Build failure during macro expansion", ex);
throw new ScalacWorker.CompilationFailed("during macro expansion", ex);
} else {
throw ex;
}
Expand Down Expand Up @@ -58,7 +58,7 @@ public static ScalacInvokerResults invokeCompiler(CompileOptions ops, String[] c

if (reporter.hasErrors()) {
reporter.flush();
throw new RuntimeException("Build failed");
throw new ScalacWorker.CompilationFailed("with errors.");
}

return results;
Expand Down
2 changes: 1 addition & 1 deletion src/java/io/bazel/rulesscala/scalac/ScalacInvoker3.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static ScalacInvokerResults invokeCompiler(CompileOptions ops, String[] c

if (reporter.hasErrors()) {
// reporter.flush();
throw new RuntimeException("Build failed");
throw new ScalacWorker.CompilationFailed("with errors.");
}

return results;
Expand Down
9 changes: 9 additions & 0 deletions src/java/io/bazel/rulesscala/scalac/ScalacWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public InvalidSettings() {
}
}

public static class CompilationFailed extends WorkerException {
public CompilationFailed(String reason, Throwable cause) {
super("Compilation failed " + reason, cause);
}
public CompilationFailed(String reason) {
this(reason, null);
}
}

private static final boolean isWindows =
System.getProperty("os.name").toLowerCase().contains("windows");

Expand Down
3 changes: 3 additions & 0 deletions src/java/io/bazel/rulesscala/worker/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public abstract class WorkerException extends RuntimeException {
public WorkerException(String message) {
super(message);
}
public WorkerException(String message, Throwable cause) {
super(message, cause);
}
}
}

Expand Down

0 comments on commit 3f0e5ba

Please sign in to comment.