Skip to content

fix: gracefully ignore broken symlinks during glob tracing#602

Open
Harshalj2108 wants to merge 3 commits into
vercel:mainfrom
Harshalj2108:fix-issue-601
Open

fix: gracefully ignore broken symlinks during glob tracing#602
Harshalj2108 wants to merge 3 commits into
vercel:mainfrom
Harshalj2108:fix-issue-601

Conversation

@Harshalj2108

Copy link
Copy Markdown

Closes #601

Problem

In environments with stale or broken symlinks (such as CentOS/Alpine containers with outdated entries in /etc/alternatives), dependency tracing fails abruptly.

The glob package natively uses fs.stat when processing directory entries (via the nodir: true flag). If a traversed directory contains a broken symlink, fs.stat throws an unhandled ENOENT error. Since this occurs deep within glob-based traversals for asset emission (src/analyze.ts) and shared library detection (src/utils/sharedlib-emit.ts), the ENOENT error propagates up and completely breaks the build.

Solution

To fix this without swallowing all exceptions or skipping valid files:

  • Added a custom filesystem wrapper (src/utils/fs-ignore-enoent.ts) that intercepts calls to native stat, lstat, and their synchronous/promise variants.
  • The wrapper specifically catches ENOENT errors (which represent broken links) and returns a mock Stats object instead of allowing the error to bubble up.
  • Updated glob calls in src/analyze.ts and src/utils/sharedlib-emit.ts to utilize this mock fs via the fs option object.

This ensures node-file-trace skips broken symlink entries gracefully rather than throwing an exception and halting the entire tracing process.

Testing

  • Verified that glob correctly bypasses the mock paths and traces neighboring assets flawlessly.
  • All existing tests should continue to pass.

Copilot AI review requested due to automatic review settings July 16, 2026 06:54
@Harshalj2108
Harshalj2108 requested review from a team, icyJoseph, ijjk and styfle as code owners July 16, 2026 06:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes dependency tracing failures caused by broken/stale symlinks encountered during glob-based traversals by injecting a custom fs implementation that suppresses ENOENT from stat/lstat calls.

Changes:

  • Added src/utils/fs-ignore-enoent.ts, an fs wrapper that catches ENOENT from stat/lstat (sync, callback, and promise variants) and returns mock Stats.
  • Updated asset/wildcard globbing in src/analyze.ts to use the wrapper via the glob({ fs }) option.
  • Updated shared library discovery in src/utils/sharedlib-emit.ts to use the same wrapper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/utils/sharedlib-emit.ts Uses the custom fs wrapper for shared library globbing to avoid broken-symlink ENOENT aborts.
src/utils/fs-ignore-enoent.ts Introduces an fs wrapper that converts ENOENT from stat calls into a mock Stats result.
src/analyze.ts Uses the wrapper for glob-based asset emission to keep tracing resilient to broken symlinks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/fs-ignore-enoent.ts
Comment thread src/utils/fs-ignore-enoent.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle broken symlinks gracefully during file tracing

2 participants