Search in sources :

Example 11 with ActionExecutionException

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;
}
Also used : FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException)

Example 12 with ActionExecutionException

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));
        }
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ByteString(com.google.protobuf.ByteString) AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) TargetOutOfDateException(com.google.devtools.build.lib.actions.TargetOutOfDateException) FileNotFoundException(java.io.FileNotFoundException) PackageRootResolutionException(com.google.devtools.build.lib.actions.PackageRootResolutionException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) Artifact(com.google.devtools.build.lib.actions.Artifact) FutureTask(java.util.concurrent.FutureTask) AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with ActionExecutionException

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;
}
Also used : AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException)

Example 14 with ActionExecutionException

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;
}
Also used : AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException)

Example 15 with ActionExecutionException

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);
    }
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) TestExecException(com.google.devtools.build.lib.actions.TestExecException) MissingInputFileException(com.google.devtools.build.lib.actions.MissingInputFileException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)26 Artifact (com.google.devtools.build.lib.actions.Artifact)15 IOException (java.io.IOException)14 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)6 AlreadyReportedActionExecutionException (com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException)6 Path (com.google.devtools.build.lib.vfs.Path)5 Map (java.util.Map)5 Test (org.junit.Test)5 Action (com.google.devtools.build.lib.actions.Action)4 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)4 Executor (com.google.devtools.build.lib.actions.Executor)4 MissingInputFileException (com.google.devtools.build.lib.actions.MissingInputFileException)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)4 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)3 ExecException (com.google.devtools.build.lib.actions.ExecException)3 ThreadCompatible (com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible)3 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)2 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)2