Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch macro expansion exceptions in ScalacWorker #1489

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/java/io/bazel/rulesscala/scalac/ScalacWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ private static String[] getPluginParamsFrom(CompileOptions ops) {
return pluginParams.toArray(new String[pluginParams.size()]);
}

private static boolean isMacroException(Throwable ex) {
for (StackTraceElement elem : ex.getStackTrace()) {
if (elem.getMethodName().equals("macroExpand")) {
return true;
}
}
return false;
}

private static void compileScalaSources(CompileOptions ops, String[] scalaSources, Path classes)
throws IOException {

Expand All @@ -269,6 +278,8 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource
} catch (Throwable ex) {
if (ex.toString().contains("scala.reflect.internal.Types$TypeError")) {
throw new RuntimeException("Build failure with type error", ex);
} else if (isMacroException(ex)) {
throw new RuntimeException("Build failure during macro expansion", ex);
} else {
throw ex;
}
Expand Down