use of com.facebook.buck.util.ExceptionWithHumanReadableMessage in project buck by facebook.
the class Build method executeAndPrintFailuresToEventBus.
public int executeAndPrintFailuresToEventBus(Iterable<BuildTarget> targetsish, boolean isKeepGoing, BuckEventBus eventBus, Console console, Optional<Path> pathToBuildReport) throws InterruptedException {
int exitCode;
try {
try {
BuildExecutionResult buildExecutionResult = executeBuild(targetsish, isKeepGoing);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildReport buildReport = new BuildReport(buildExecutionResult, pathResolver);
if (isKeepGoing) {
String buildReportText = buildReport.generateForConsole(console);
buildReportText = buildReportText.isEmpty() ? "Failure report is empty." : // Remove trailing newline from build report.
buildReportText.substring(0, buildReportText.length() - 1);
eventBus.post(ConsoleEvent.info(buildReportText));
exitCode = buildExecutionResult.getFailures().isEmpty() ? 0 : 1;
if (exitCode != 0) {
eventBus.post(ConsoleEvent.severe("Not all rules succeeded."));
}
} else {
exitCode = 0;
}
if (pathToBuildReport.isPresent()) {
// Note that pathToBuildReport is an absolute path that may exist outside of the project
// root, so it is not appropriate to use ProjectFilesystem to write the output.
String jsonBuildReport = buildReport.generateJsonBuildReport();
try {
Files.write(jsonBuildReport, pathToBuildReport.get().toFile(), Charsets.UTF_8);
} catch (IOException e) {
eventBus.post(ThrowableConsoleEvent.create(e, "Failed writing report"));
exitCode = 1;
}
}
} catch (ExecutionException | RuntimeException e) {
// This is likely a checked exception that was caught while building a build rule.
Throwable cause = e.getCause();
if (cause == null) {
Throwables.throwIfInstanceOf(e, RuntimeException.class);
throw new RuntimeException(e);
}
Throwables.throwIfInstanceOf(cause, IOException.class);
Throwables.throwIfInstanceOf(cause, StepFailedException.class);
Throwables.throwIfInstanceOf(cause, InterruptedException.class);
Throwables.throwIfInstanceOf(cause, ClosedByInterruptException.class);
Throwables.throwIfInstanceOf(cause, HumanReadableException.class);
if (cause instanceof ExceptionWithHumanReadableMessage) {
throw new HumanReadableException((ExceptionWithHumanReadableMessage) cause);
}
LOG.debug(e, "Got an exception during the build.");
throw new RuntimeException(e);
}
} catch (IOException e) {
LOG.debug(e, "Got an exception during the build.");
eventBus.post(ConsoleEvent.severe(getFailureMessageWithClassName(e)));
exitCode = 1;
} catch (StepFailedException e) {
LOG.debug(e, "Got an exception during the build.");
eventBus.post(ConsoleEvent.severe(getFailureMessage(e)));
exitCode = 1;
}
return exitCode;
}
Aggregations