use of com.google.devtools.build.lib.actions.ActionExecutionException in project bazel by bazelbuild.
the class SkyframeActionExecutor method executeActionTask.
/**
* Execute the specified action, in a profiler task.
* The caller is responsible for having already checked that we need to
* execute it and for acquiring/releasing any scheduling locks needed.
*
* <p>This is thread-safe so long as you don't try to execute the same action
* twice at the same time (or overlapping times).
* May execute in a worker thread.
*
* @throws ActionExecutionException if the execution of the specified action
* failed for any reason.
* @throws InterruptedException if the thread was interrupted.
* @return true if the action output was dumped, false otherwise.
*/
private boolean executeActionTask(Action action, ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
profiler.startTask(ProfilerTask.ACTION_EXECUTE, action);
// ActionExecutionExceptions that occur as the thread is interrupted are
// assumed to be a result of that, so we throw InterruptedException
// instead.
FileOutErr outErrBuffer = actionExecutionContext.getFileOutErr();
try {
action.execute(actionExecutionContext);
// current implementation it uses regular expression matching.
if (outErrBuffer.hasRecordedOutput() && (action.showsOutputUnconditionally() || reporter.showOutput(Label.print(action.getOwner().getLabel())))) {
dumpRecordedOutErr(action, outErrBuffer);
return true;
}
// Defer reporting action success until outputs are checked
} catch (ActionExecutionException e) {
processAndThrow(e, action, outErrBuffer);
} finally {
profiler.completeTask(ProfilerTask.ACTION_EXECUTE);
}
return false;
}
use of com.google.devtools.build.lib.actions.ActionExecutionException in project bazel by bazelbuild.
the class SkyframeActionExecutor method executeAction.
/**
* Executes the provided action on the current thread. Returns the ActionExecutionValue with the
* result, either computed here or already computed on another thread.
*
* <p>For use from {@link ArtifactFunction} only.
*/
ActionExecutionValue executeAction(Action action, ActionMetadataHandler metadataHandler, long actionStartTime, ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
Exception exception = badActionMap.get(action);
if (exception != null) {
// If action had a conflict with some other action in the graph, report it now.
reportError(exception.getMessage(), exception, action, null);
}
Artifact primaryOutput = action.getPrimaryOutput();
FutureTask<ActionExecutionValue> actionTask = new FutureTask<>(new ActionRunner(action, metadataHandler, actionStartTime, actionExecutionContext));
// Check to see if another action is already executing/has executed this value.
Pair<Action, FutureTask<ActionExecutionValue>> oldAction = buildActionMap.putIfAbsent(primaryOutput, Pair.of(action, actionTask));
if (oldAction == null) {
actionTask.run();
} else {
Preconditions.checkState(action != oldAction.first, action);
Preconditions.checkState(Actions.canBeShared(oldAction.first, action), "Actions cannot be shared: %s %s", oldAction.first, action);
// Wait for other action to finish, so any actions that depend on its outputs can execute.
actionTask = oldAction.second;
}
try {
return actionTask.get();
} catch (ExecutionException e) {
Throwables.propagateIfPossible(e.getCause(), ActionExecutionException.class, InterruptedException.class);
throw new IllegalStateException(e);
} finally {
String message = action.getProgressMessage();
if (message != null) {
// completion messages are enabled (--show_task_finish).
if (completionReceiver != null) {
completionReceiver.actionCompleted(action);
}
reporter.finishTask(null, prependExecPhaseStats(message));
}
}
}
use of com.google.devtools.build.lib.actions.ActionExecutionException in project bazel by bazelbuild.
the class SkyframeActionExecutor method processAndThrow.
ActionExecutionException processAndThrow(ActionExecutionException e, Action action, FileOutErr outErrBuffer) throws ActionExecutionException {
reportActionExecution(action, e, outErrBuffer);
boolean reported = reportErrorIfNotAbortingMode(e, outErrBuffer);
ActionExecutionException toThrow = e;
if (reported) {
// If we already printed the error for the exception we mark it as already reported
// so that we do not print it again in upper levels.
// Note that we need to report it here since we want immediate feedback of the errors
// and in some cases the upper-level printing mechanism only prints one of the errors.
toThrow = new AlreadyReportedActionExecutionException(e);
}
// exit status of any actions that had finished in the meantime.
throw toThrow;
}
use of com.google.devtools.build.lib.actions.ActionExecutionException in project bazel by bazelbuild.
the class SkyframeActionExecutor method reportError.
/**
* Convenience function for reporting that the action failed due to a
* the exception cause, if there is an additional explanatory message that
* clarifies the message of the exception. Combines the user-provided message
* and the exceptions' message and reports the combination as error.
* Then, throws an ActionExecutionException with the reported error as
* message and the provided exception as the cause.
*
* @param message A small text that explains why the action failed
* @param cause The exception that caused the action to fail
* @param action The action that failed
* @param actionOutput The output of the failed Action.
* May be null, if there is no output to display
*/
private void reportError(String message, Throwable cause, Action action, FileOutErr actionOutput) throws ActionExecutionException {
ActionExecutionException ex;
if (cause == null) {
ex = new ActionExecutionException(message, action, false);
} else {
ex = new ActionExecutionException(message, cause, action, false);
}
printError(ex.getMessage(), action, actionOutput);
throw ex;
}
use of com.google.devtools.build.lib.actions.ActionExecutionException in project bazel by bazelbuild.
the class SkyframeBuilder method rethrow.
/** Figure out why an action's execution failed and rethrow the right kind of exception. */
@VisibleForTesting
public static void rethrow(Throwable cause) throws BuildFailedException, TestExecException {
Throwable innerCause = cause.getCause();
if (innerCause instanceof TestExecException) {
throw (TestExecException) innerCause;
}
if (cause instanceof ActionExecutionException) {
ActionExecutionException actionExecutionCause = (ActionExecutionException) cause;
// Sometimes ActionExecutionExceptions are caused by Actions with no owner.
String message = (actionExecutionCause.getLocation() != null) ? (actionExecutionCause.getLocation().print() + " " + cause.getMessage()) : cause.getMessage();
throw new BuildFailedException(message, actionExecutionCause.isCatastrophe(), actionExecutionCause.getAction(), actionExecutionCause.getRootCauses(), /*errorAlreadyShown=*/
!actionExecutionCause.showError(), actionExecutionCause.getExitCode());
} else if (cause instanceof MissingInputFileException) {
throw new BuildFailedException(cause.getMessage());
} else if (cause instanceof BuildFileNotFoundException) {
// Sadly, this can happen because we may load new packages during input discovery. Any
// failures reading those packages shouldn't terminate the build, but in Skyframe they do.
LoggingUtil.logToRemote(Level.WARNING, "undesirable loading exception", cause);
throw new BuildFailedException(cause.getMessage());
} else if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Error) {
throw (Error) cause;
} else {
// expectations in this method.
throw new IllegalArgumentException("action terminated with " + "unexpected exception: " + cause.getMessage(), cause);
}
}
Aggregations