Update error handling for absolute symlink violations when evaluating a fileset.

PiperOrigin-RevId: 687311869
Change-Id: I2f481f7a702494691093bf91905fbb28f309a482
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
index d703084..8a24daf 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
@@ -375,6 +375,12 @@
               String.format(
                   "Generated conflict in source tree: %s %s %s", artifact, fileValue, request),
               e);
+        // TODO: b/7075837 - This code path is possible when BAZEL_TRACK_SOURCE_DIRECTORIES is set.
+        case DETAILED_IO_EXCEPTION:
+          throw new IllegalStateException(
+              String.format(
+                  "%s: %s %s %s", e.getCause().getMessage(), artifact, fileValue, request),
+              e);
       }
       throw new IllegalStateException("Can't get here", e);
     }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index 6aec2b6..1a8cd4e 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -47,6 +47,7 @@
 import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
 import com.google.devtools.build.lib.util.Fingerprint;
+import com.google.devtools.build.lib.vfs.DetailedIOException;
 import com.google.devtools.build.lib.vfs.Dirent;
 import com.google.devtools.build.lib.vfs.FileStatus;
 import com.google.devtools.build.lib.vfs.Path;
@@ -109,13 +110,22 @@
 
       /** The filesystem told us inconsistent information. */
       INCONSISTENT_FILESYSTEM,
+
+      /** The filesystem threw a {@link DetailedIOException}. */
+      DETAILED_IO_EXCEPTION,
     }
 
     private final RecursiveFilesystemTraversalException.Type type;
 
+    RecursiveFilesystemTraversalException(String message, DetailedIOException cause) {
+      super(message, cause);
+      this.type = RecursiveFilesystemTraversalException.Type.DETAILED_IO_EXCEPTION;
+    }
+
     RecursiveFilesystemTraversalException(
         String message, RecursiveFilesystemTraversalException.Type type) {
       super(message);
+      checkArgument(type != Type.DETAILED_IO_EXCEPTION);
       this.type = type;
     }
 
@@ -250,6 +260,12 @@
           String.format(
               "Error while traversing directory %s: %s",
               traversal.root().getRelativePart(), e.getMessage());
+
+      if (e instanceof DetailedIOException detailedException) {
+        throw new RecursiveFilesystemTraversalFunctionException(
+            new RecursiveFilesystemTraversalException(message, detailedException));
+      }
+
       // Trying to stat the starting point of this root may have failed with a symlink cycle or
       // trying to get a package lookup value may have failed due to a symlink cycle.
       RecursiveFilesystemTraversalException.Type exceptionType =