Skip to content

Commit

Permalink
Add more logging to exception
Browse files Browse the repository at this point in the history
We are seeing reports of an exception triggered due to unknown entries being
present in the sandbox base. Without actually knowing what those
files/directories are it is hard to know the next steps, for example if more
entries should be added to the allowlist SANDBOX_BASE_PERSISTENT_DIRS or if the
precondition check should be removed altogether.

This change adds more logging to get the names of the entries

RELNOTES:none
PiperOrigin-RevId: 621118864
Change-Id: Ie606f12a4148490d2c218ef5ba84605218e4f919
  • Loading branch information
oquenchil authored and copybara-github committed Apr 2, 2024
1 parent ac29a5a commit b9741ed
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;

import com.google.common.base.Preconditions;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -526,13 +526,19 @@ public void cleanStarting(@SuppressWarnings("unused") CleanStartingEvent event)
*/
private static void checkSandboxBaseTopOnlyContainsPersistentDirs(Path sandboxBase) {
try {
Preconditions.checkState(
SANDBOX_BASE_PERSISTENT_DIRS.containsAll(
sandboxBase.getDirectoryEntries().stream()
.map(Path::getBaseName)
.collect(toImmutableList())),
"Found unexpected files in sandbox base. Please report this in"
+ " https://github.com/bazelbuild/bazel/issues.");
ImmutableList<String> directoryEntries =
sandboxBase.getDirectoryEntries().stream()
.map(Path::getBaseName)
.collect(toImmutableList());
if (!SANDBOX_BASE_PERSISTENT_DIRS.containsAll(directoryEntries)) {
StringBuilder message =
new StringBuilder(
"Found unexpected entries in sandbox base. Please report this in"
+ " https://github.com/bazelbuild/bazel/issues.");
message.append(" The entries are: ");
Joiner.on(", ").appendTo(message, directoryEntries);
throw new IllegalStateException(message.toString());
}
} catch (IOException e) {
logger.atWarning().withCause(e).log("Failed to clean up sandbox base %s", sandboxBase);
}
Expand Down

0 comments on commit b9741ed

Please sign in to comment.