From fae4e25539969671c82a4d56cfb0b50761b833a3 Mon Sep 17 00:00:00 2001 From: rudrakshagarwal4200-ai Date: Sat, 17 Oct 2026 02:07:05 +0530 Subject: [PATCH] Improve error handling for symbolic links Handle errors when reading symbolic links in FilesystemSnapshot. --- src/process/capture/FilesystemSnapshot.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/process/capture/FilesystemSnapshot.ts b/src/process/capture/FilesystemSnapshot.ts index 60bee8fd5b..f65801557b 100644 --- a/src/process/capture/FilesystemSnapshot.ts +++ b/src/process/capture/FilesystemSnapshot.ts @@ -225,8 +225,23 @@ export const snapshotRoots = async ( const relativePath = relative(root, path) || "."; if (stats.isSymbolicLink()) { // Keep the target as stored: lexical resolution can merge distinct targets. - const target = await readlink(path); - const afterRead = await lstat(path); + let target: string; + let afterRead: Stats; + try { + target = await readlink(path); + afterRead = await lstat(path); + } catch (cause: unknown) { + if ( + cause instanceof Error && + "code" in cause && + cause.code === "ENOENT" + ) { + truncated = true; + enumerationReasons.add("identity_changed"); + return false; + } + throw cause; + } if (!hasSameIdentity(stats, afterRead, "symlink")) { truncated = true; enumerationReasons.add("identity_changed");