|
24 | 24 | import com.google.devtools.build.lib.skyframe.DetailedException;
|
25 | 25 | import com.google.devtools.build.lib.util.DetailedExitCode;
|
26 | 26 | import com.google.devtools.build.lib.util.ExitCode;
|
| 27 | +import javax.annotation.Nullable; |
27 | 28 | import net.starlark.java.syntax.Location;
|
28 | 29 |
|
29 | 30 | /**
|
@@ -115,6 +116,47 @@ private static NestedSet<Cause> rootCausesFromAction(
|
115 | 116 | detailedExitCode));
|
116 | 117 | }
|
117 | 118 |
|
| 119 | + public static ActionExecutionException fromExecException(ExecException exception, Action action) { |
| 120 | + return fromExecException(exception, null, action); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Returns a new ActionExecutionException given an optional action subtask describing which part |
| 125 | + * of the action failed (should be null for standard action failures). When appropriate (we use |
| 126 | + * some heuristics to decide), produces an abbreviated message incorporating just the termination |
| 127 | + * status if available. |
| 128 | + * |
| 129 | + * @param exception initial ExecException |
| 130 | + * @param actionSubtask additional information about the action |
| 131 | + * @param action failed action |
| 132 | + * @return ActionExecutionException object describing the action failure |
| 133 | + */ |
| 134 | + public static ActionExecutionException fromExecException( |
| 135 | + ExecException exception, @Nullable String actionSubtask, Action action) { |
| 136 | + // Message from ActionExecutionException will be prepended with action.describe() where |
| 137 | + // necessary: because not all ActionExecutionExceptions come from this codepath, it is safer |
| 138 | + // for consumers to manually prepend. We still put action.describe() in the failure detail |
| 139 | + // message argument. |
| 140 | + String message = |
| 141 | + (actionSubtask == null ? "" : actionSubtask + ": ") |
| 142 | + + exception.getMessageForActionExecutionException(); |
| 143 | + |
| 144 | + DetailedExitCode code = |
| 145 | + DetailedExitCode.of(exception.getFailureDetail(action.describe() + " failed: " + message)); |
| 146 | + |
| 147 | + if (exception instanceof LostInputsExecException) { |
| 148 | + return ((LostInputsExecException) exception).fromExecException(message, action, code); |
| 149 | + } |
| 150 | + |
| 151 | + return fromExecException(exception, message, action, code); |
| 152 | + } |
| 153 | + |
| 154 | + public static ActionExecutionException fromExecException( |
| 155 | + ExecException exception, String message, Action action, DetailedExitCode code) { |
| 156 | + return new ActionExecutionException( |
| 157 | + message, exception, action, exception.isCatastrophic(), code); |
| 158 | + } |
| 159 | + |
118 | 160 | /** Returns the action that failed. */
|
119 | 161 | public ActionAnalysisMetadata getAction() {
|
120 | 162 | return action;
|
|
0 commit comments