Fix up exception declarations; use EnvironmentalExecException.
--
MOS_MIGRATED_REVID=109404922
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
index c9da45f..f0b1baa 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
@@ -24,6 +24,7 @@
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.ActionInputHelper;
import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.actions.EnvironmentalExecException;
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.ExecutionStrategy;
import com.google.devtools.build.lib.actions.Executor;
@@ -122,16 +123,10 @@
// Gather all necessary mounts for the sandbox.
mounts = getMounts(spawn, actionExecutionContext);
} catch (IllegalArgumentException | IOException e) {
- throw new UserExecException("Could not prepare mounts for sandbox execution", e);
+ throw new EnvironmentalExecException("Could not prepare mounts for sandbox execution", e);
}
- ImmutableSet<Path> createDirs;
- try {
- createDirs = createImportantDirs(spawn.getEnvironment());
- } catch (IOException e) {
- throw new UserExecException(
- "Could not prepare the set of important directories to create in the sandbox", e);
- }
+ ImmutableSet<Path> createDirs = createImportantDirs(spawn.getEnvironment());
int timeout = getTimeout(spawn);
@@ -178,7 +173,7 @@
}
}
- private int getTimeout(Spawn spawn) throws UserExecException {
+ private int getTimeout(Spawn spawn) throws ExecException {
String timeoutStr = spawn.getExecutionInfo().get("timeout");
if (timeoutStr != null) {
try {
@@ -196,7 +191,7 @@
* <p>Note that $HOME is handled by namespace-sandbox.c, because it changes user to nobody and the
* home directory of that user is not known by us.
*/
- private ImmutableSet<Path> createImportantDirs(Map<String, String> env) throws IOException {
+ private ImmutableSet<Path> createImportantDirs(Map<String, String> env) {
ImmutableSet.Builder<Path> dirs = ImmutableSet.builder();
FileSystem fs = blazeDirs.getFileSystem();
if (env.containsKey("TEST_TMPDIR")) {
@@ -207,7 +202,7 @@
}
private ImmutableMap<Path, Path> getMounts(Spawn spawn, ActionExecutionContext executionContext)
- throws IOException, UserExecException {
+ throws IOException, ExecException {
MountMap mounts = new MountMap();
mounts.putAll(mountUsualUnixDirs());
mounts.putAll(withRecursedDirs(setupBlazeUtils()));
@@ -314,7 +309,7 @@
/**
* Mount the embedded tools.
*/
- private MountMap setupBlazeUtils() throws IOException {
+ private MountMap setupBlazeUtils() {
MountMap mounts = new MountMap();
Path mount = blazeDirs.getEmbeddedBinariesRoot().getRelative("build-runfiles");
mounts.put(mount, mount);
@@ -324,7 +319,7 @@
/**
* Mount all runfiles that the spawn needs as specified in its runfiles manifests.
*/
- private MountMap mountRunfilesFromManifests(Spawn spawn) throws IOException, UserExecException {
+ private MountMap mountRunfilesFromManifests(Spawn spawn) throws IOException, ExecException {
MountMap mounts = new MountMap();
for (Entry<PathFragment, Artifact> manifest : spawn.getRunfilesManifests().entrySet()) {
String manifestFilePath = manifest.getValue().getPath().getPathString();
@@ -340,7 +335,7 @@
* Mount all files that the spawn needs as specified in its fileset manifests.
*/
private MountMap mountFilesFromFilesetManifests(
- Spawn spawn, ActionExecutionContext executionContext) throws IOException, UserExecException {
+ Spawn spawn, ActionExecutionContext executionContext) throws IOException, ExecException {
final FilesetActionContext filesetContext =
executionContext.getExecutor().getContext(FilesetActionContext.class);
MountMap mounts = new MountMap();
@@ -358,7 +353,7 @@
static MountMap parseManifestFile(
Path targetDirectory, File manifestFile, boolean isFilesetManifest, String workspaceName)
- throws IOException, UserExecException {
+ throws IOException, ExecException {
MountMap mounts = new MountMap();
int lineNum = 0;
for (String line : Files.readLines(manifestFile, StandardCharsets.UTF_8)) {
@@ -376,7 +371,8 @@
PathFragment targetPathFragment = new PathFragment(fields[0]);
if (!workspaceName.isEmpty()) {
if (!targetPathFragment.getSegment(0).equals(workspaceName)) {
- throw new UserExecException("Fileset manifest line must start with workspace name");
+ throw new EnvironmentalExecException(
+ "Fileset manifest line must start with workspace name");
}
targetPathFragment = targetPathFragment.subFragment(1, targetPathFragment.segmentCount());
}
@@ -428,8 +424,7 @@
/**
* Mount all inputs of the spawn.
*/
- private MountMap mountInputs(Spawn spawn, ActionExecutionContext actionExecutionContext)
- throws IOException {
+ private MountMap mountInputs(Spawn spawn, ActionExecutionContext actionExecutionContext) {
MountMap mounts = new MountMap();
List<ActionInput> inputs =
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/NamespaceSandboxRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/NamespaceSandboxRunner.java
index 99c1093..a9722ea 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/NamespaceSandboxRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/NamespaceSandboxRunner.java
@@ -19,6 +19,7 @@
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import com.google.devtools.build.lib.actions.ActionInput;
+import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.UserExecException;
import com.google.devtools.build.lib.analysis.config.BinTools;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
@@ -104,7 +105,7 @@
* @param env - environment to run sandbox in
* @param cwd - current working directory
* @param outErr - error output to capture sandbox's and command's stderr
- * @throws CommandException
+ * @throws ExecException
*/
public void run(
List<String> spawnArguments,
@@ -114,7 +115,7 @@
Collection<? extends ActionInput> outputs,
int timeout,
boolean blockNetwork)
- throws IOException, UserExecException {
+ throws IOException, ExecException {
createFileSystem(outputs);
List<String> fileArgs = new ArrayList<>();
diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTest.java b/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTest.java
index 94494e3..daed53e 100644
--- a/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTest.java
@@ -19,7 +19,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
-import com.google.devtools.build.lib.actions.UserExecException;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -68,12 +67,12 @@
* output of {@code LinuxSandboxedStrategy#fixMounts} for it.
*/
private ImmutableMap<String, String> userFriendlyMounts(
- Map<String, String> linksAndFiles, List<String> customMounts) throws IOException {
+ Map<String, String> linksAndFiles, List<String> customMounts) throws Exception {
return userFriendlyMap(mounts(linksAndFiles, customMounts));
}
private ImmutableMap<Path, Path> mounts(
- Map<String, String> linksAndFiles, List<String> customMounts) throws IOException {
+ Map<String, String> linksAndFiles, List<String> customMounts) throws Exception {
createTreeStructure(linksAndFiles);
ImmutableMap.Builder<Path, Path> mounts = ImmutableMap.builder();
@@ -92,11 +91,11 @@
* the output of {@code LinuxSandboxedStrategy#fixMounts} for it.
*/
private Map<String, String> userFriendlyMounts(Map<String, String> linksAndFiles)
- throws IOException {
+ throws Exception {
return userFriendlyMap(mounts(linksAndFiles));
}
- private Map<Path, Path> mounts(Map<String, String> linksAndFiles) throws IOException {
+ private Map<Path, Path> mounts(Map<String, String> linksAndFiles) throws Exception {
return mounts(
linksAndFiles, ImmutableList.of(Iterables.getFirst(linksAndFiles.keySet(), null)));
}
@@ -118,7 +117,7 @@
return pathifiedAsserts.build();
}
- private void createTreeStructure(Map<String, String> linksAndFiles) throws IOException {
+ private void createTreeStructure(Map<String, String> linksAndFiles) throws Exception {
for (Entry<String, String> entry : linksAndFiles.entrySet()) {
Path filePath = workspaceDir.getRelative(entry.getKey());
String linkTarget = entry.getValue();
@@ -136,7 +135,7 @@
}
@Test
- public void testResolvesRelativeFileToFileSymlinkInSameDir() throws IOException {
+ public void testResolvesRelativeFileToFileSymlinkInSameDir() throws Exception {
Map<String, String> testFiles = new LinkedHashMap<>();
testFiles.put("symlink.txt", "goal.txt");
testFiles.put("goal.txt", "");
@@ -149,7 +148,7 @@
}
@Test
- public void testResolvesRelativeFileToFileSymlinkInSubDir() throws IOException {
+ public void testResolvesRelativeFileToFileSymlinkInSubDir() throws Exception {
Map<String, String> testFiles =
ImmutableMap.of(
"symlink.txt", "x/goal.txt",
@@ -160,7 +159,7 @@
}
@Test
- public void testResolvesRelativeFileToFileSymlinkInParentDir() throws IOException {
+ public void testResolvesRelativeFileToFileSymlinkInParentDir() throws Exception {
Map<String, String> testFiles =
ImmutableMap.of(
"x/symlink.txt", "../goal.txt",
@@ -172,7 +171,7 @@
}
@Test
- public void testRecursesSubDirs() throws IOException {
+ public void testRecursesSubDirs() throws Exception {
ImmutableList<String> inputFile = ImmutableList.of("a/b");
Map<String, String> testFiles =
@@ -191,7 +190,7 @@
* Test that the algorithm correctly identifies and refuses symlink loops.
*/
@Test
- public void testCatchesSymlinkLoop() throws IOException {
+ public void testCatchesSymlinkLoop() throws Exception {
try {
mounts(
ImmutableMap.of(
@@ -212,7 +211,7 @@
* directories (e.g. "a -> dir/file/file").
*/
@Test
- public void testCatchesIllegalSymlink() throws IOException {
+ public void testCatchesIllegalSymlink() throws Exception {
try {
mounts(
ImmutableMap.of(
@@ -228,7 +227,7 @@
}
@Test
- public void testParseManifestFile() throws IOException, UserExecException {
+ public void testParseManifestFile() throws Exception {
Path targetDir = workspaceDir.getRelative("runfiles");
targetDir.createDirectory();
@@ -255,7 +254,7 @@
}
@Test
- public void testParseFilesetManifestFile() throws IOException, UserExecException {
+ public void testParseFilesetManifestFile() throws Exception {
Path targetDir = workspaceDir.getRelative("fileset");
targetDir.createDirectory();