Skip to content

Commit

Permalink
Convert SingleExtensionEvalFunctions's use of IOException to an
Browse files Browse the repository at this point in the history
ExternalDepsException.

Part of bazelbuild#18629.
  • Loading branch information
katre committed Jun 12, 2023
1 parent 1f18b19 commit 022f464
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.google.devtools.build.lib.rules.repository.NeedsSkyframeRestartException;
import com.google.devtools.build.lib.runtime.ProcessWrapper;
import com.google.devtools.build.lib.runtime.RepositoryRemoteExecutor;
import com.google.devtools.build.lib.server.FailureDetails.ExternalDeps.Code;
import com.google.devtools.build.lib.server.FailureDetails.ExternalDeps;
import com.google.devtools.build.lib.skyframe.BzlLoadFunction;
import com.google.devtools.build.lib.skyframe.BzlLoadFunction.BzlLoadFailedException;
import com.google.devtools.build.lib.skyframe.BzlLoadValue;
Expand Down Expand Up @@ -115,7 +115,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
} catch (LabelSyntaxException e) {
throw new SingleExtensionEvalFunctionException(
ExternalDepsException.withCauseAndMessage(
Code.BAD_MODULE, e, "invalid module extension label"),
ExternalDeps.Code.BAD_MODULE, e, "invalid module extension label"),
Transience.PERSISTENT);
}

Expand All @@ -130,7 +130,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
} catch (BzlLoadFailedException e) {
throw new SingleExtensionEvalFunctionException(
ExternalDepsException.withCauseAndMessage(
Code.BAD_MODULE,
ExternalDeps.Code.BAD_MODULE,
e,
"Error loading '%s' for module extensions, requested by %s: %s",
extensionId.getBzlFileLabel(),
Expand All @@ -156,7 +156,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
.collect(toImmutableSet());
throw new SingleExtensionEvalFunctionException(
ExternalDepsException.withMessage(
Code.BAD_MODULE,
ExternalDeps.Code.BAD_MODULE,
"%s does not export a module extension called %s, yet its use is requested at %s%s",
extensionId.getBzlFileLabel(),
extensionId.getExtensionName(),
Expand Down Expand Up @@ -188,7 +188,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
if (returnValue != Starlark.NONE && !(returnValue instanceof ModuleExtensionMetadata)) {
throw new SingleExtensionEvalFunctionException(
ExternalDepsException.withMessage(
Code.BAD_MODULE,
ExternalDeps.Code.BAD_MODULE,
"expected module extension %s in %s to return None or extension_metadata, got %s",
extensionId.getExtensionName(),
extensionId.getBzlFileLabel(),
Expand All @@ -209,14 +209,20 @@ public SkyValue compute(SkyKey skyKey, Environment env)
moduleContext.getWorkingDirectory().deleteTree();
}
} catch (IOException e1) {
throw new SingleExtensionEvalFunctionException(e1, Transience.TRANSIENT);
ExternalDepsException externalDepsException =
ExternalDepsException.withCauseAndMessage(
ExternalDeps.Code.UNRECOGNIZED,
e1,
"Failed to clean up module context directory");
throw new SingleExtensionEvalFunctionException(
externalDepsException, Transience.TRANSIENT);
}
return null;
} catch (EvalException e) {
env.getListener().handle(Event.error(e.getMessageWithStack()));
throw new SingleExtensionEvalFunctionException(
ExternalDepsException.withMessage(
Code.BAD_MODULE,
ExternalDeps.Code.BAD_MODULE,
"error evaluating module extension %s in %s",
extensionId.getExtensionName(),
extensionId.getBzlFileLabel()),
Expand All @@ -230,7 +236,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
if (!threadContext.getGeneratedRepoSpecs().containsKey(repoImport.getValue())) {
throw new SingleExtensionEvalFunctionException(
ExternalDepsException.withMessage(
Code.BAD_MODULE,
ExternalDeps.Code.BAD_MODULE,
"module extension \"%s\" from \"%s\" does not generate repository \"%s\", yet it"
+ " is imported as \"%s\" in the usage at %s%s",
extensionId.getExtensionName(),
Expand Down Expand Up @@ -300,9 +306,5 @@ static final class SingleExtensionEvalFunctionException extends SkyFunctionExcep
SingleExtensionEvalFunctionException(ExternalDepsException cause, Transience transience) {
super(cause, transience);
}

SingleExtensionEvalFunctionException(IOException cause, Transience transience) {
super(cause, transience);
}
}
}

0 comments on commit 022f464

Please sign in to comment.