Skip to content

Commit

Permalink
Stacktrace for errors when finalizing processors (#10467)
Browse files Browse the repository at this point in the history
The TypeElementVisitorProcessor calls the `.finish()` method on visitors and catches all exceptions if present. But the message might not be descriptive enough. For example a StackOverflowError does not have a message, so the logs would be:
`[ERROR] error: Error finalizing type visitor [...Visitor@5e67a490]: null`
Since the visitors are not expected to fail frequently, printing stack trace should not have a negative impact on performance.
  • Loading branch information
andriy-dmytruk authored Feb 8, 2024
1 parent cfd6449 commit ca0f0e7
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -278,7 +280,11 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
try {
loadedVisitor.getVisitor().finish(javaVisitorContext);
} catch (Throwable e) {
error("Error finalizing type visitor [%s]: %s", loadedVisitor.getVisitor(), e.getMessage());
StringWriter stackTraceWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stackTraceWriter));

error("Error finalizing type visitor [%s]: %s\n%s",
loadedVisitor.getVisitor(), e.getMessage(), stackTraceWriter);
}
}
}
Expand Down

0 comments on commit ca0f0e7

Please sign in to comment.