if (result instanceof Failure) {
// Could potentially distinguish between CommandFailure and DaemonFailure here.
Throwable failure = ((Failure) result).getValue();
if (failure instanceof DaemonStoppedException && cancellationToken.isCancellationRequested()) {
LOGGER.error("Daemon was stopped to handle build cancel request.");
throw new BuildCancelledException();
}
throw UncheckedException.throwAsUncheckedException(failure);
} else if (result instanceof DaemonUnavailable) {
throw new DaemonInitialConnectException("The daemon we connected to was unavailable: " + ((DaemonUnavailable) result).getReason());
} else if (result instanceof Result) {