fix: gracefully ignore broken symlinks during glob tracing#602
Open
Harshalj2108 wants to merge 3 commits into
Open
fix: gracefully ignore broken symlinks during glob tracing#602Harshalj2108 wants to merge 3 commits into
Harshalj2108 wants to merge 3 commits into
Conversation
Harshalj2108
requested review from
a team,
icyJoseph,
ijjk and
styfle
as code owners
July 16, 2026 06:54
There was a problem hiding this comment.
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, anfswrapper that catchesENOENTfromstat/lstat(sync, callback, and promise variants) and returns mockStats. - Updated asset/wildcard globbing in
src/analyze.tsto use the wrapper via theglob({ fs })option. - Updated shared library discovery in
src/utils/sharedlib-emit.tsto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #601
Problem
In environments with stale or broken symlinks (such as
CentOS/Alpinecontainers with outdated entries in/etc/alternatives), dependency tracing fails abruptly.The
globpackage natively usesfs.statwhen processing directory entries (via thenodir: trueflag). If a traversed directory contains a broken symlink,fs.statthrows an unhandledENOENTerror. Since this occurs deep within glob-based traversals for asset emission (src/analyze.ts) and shared library detection (src/utils/sharedlib-emit.ts), theENOENTerror propagates up and completely breaks the build.Solution
To fix this without swallowing all exceptions or skipping valid files:
src/utils/fs-ignore-enoent.ts) that intercepts calls to nativestat,lstat, and their synchronous/promise variants.ENOENTerrors (which represent broken links) and returns a mockStatsobject instead of allowing the error to bubble up.globcalls insrc/analyze.tsandsrc/utils/sharedlib-emit.tsto utilize this mockfsvia thefsoption object.This ensures
node-file-traceskips broken symlink entries gracefully rather than throwing an exception and halting the entire tracing process.Testing
globcorrectly bypasses the mock paths and traces neighboring assets flawlessly.