Skip to content

fix: suppress stats errors for unstat-able paths in watch-event path#326

Open
danielroe wants to merge 1 commit into
webpack:mainfrom
danielroe:fix/stats-einval
Open

fix: suppress stats errors for unstat-able paths in watch-event path#326
danielroe wants to merge 1 commit into
webpack:mainfrom
danielroe:fix/stats-einval

Conversation

@danielroe

@danielroe danielroe commented Jul 20, 2026

Copy link
Copy Markdown

Summary

this ignores EINVAL, EACCES and ENODEV lstat errors on watch events, following up on #298

we noticed in this in CI (search for EINVAL in the logs)

this is a harmless situation and the fact that we already resolved #187 for initial scan suggests it's safe to do the same for watch events, and with the same motivation.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

yes

Does this PR introduce a breaking change?

no

Use of AI

I used AI to:

  1. identify the cause of the log I was seeing in CI
  2. identify the lines of code responsible for the error
  3. search for similar issues or pull requests before opening this one

Copilot AI review requested due to automatic review settings July 20, 2026 14:51
@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 999dc1d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
watchpack Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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

This PR extends Watchpack’s existing “permission/invalid-path” error suppression from the initial scan path to the watch-event path, preventing noisy Watchpack Error (stats) logs when lstat fails with known “unstat-able” error codes (e.g. protected Windows system files, unreadable mounts).

Changes:

  • Suppress onStatsError logging for EACCES, ENODEV, and Windows-only EINVAL during watch events in DirectoryWatcher.
  • Add Jest coverage to assert no stats-error logging occurs for these watch-event lstat failures.
  • Add a changeset documenting the patch-level behavior change.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/DirectoryWatcher.js Suppresses specific lstat error codes in the watch-event path, aligning behavior with initial scan suppression.
test/DirectoryWatcher.test.js Adds regression tests ensuring suppressed lstat errors during watch events do not log Watchpack Error (stats).
.changeset/silence-stats-errors-watch-events.md Documents the patch change in release notes.

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

Comment on lines +394 to +404
testHelper.tick(500, () => {
// eslint-disable-next-line jsdoc/reject-any-type
/** @type {any} */ (fs).lstat = originalLstat;
a.close();
const printed = errorSpy.mock.calls
.map((call) => String(call[0]))
.filter((msg) => msg.includes("Watchpack Error (stats)"));
errorSpy.mockRestore();
expect(printed).toEqual([]);
done();
});

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm not sure this is true.

@alexander-akait

Copy link
Copy Markdown
Member

@danielroe Thanks for the PR, can you describe cases when you are getting them?

@danielroe

danielroe commented Jul 20, 2026

Copy link
Copy Markdown
Author

I think the scenario is that:

  • we are running the dev server in hmr tests on windows
  • a dependency can't be resolved, so webpack looks up and up and up to the root (D:/ in the runner)
  • we make some changes deliberately to trigger the watcher
  • watchpack fires on all the paths it looked up on

you can see in the logs: https://github.com/nuxt/nuxt/actions/runs/29737171552/job/88355542839?pr=35740#step:7:1813

you can ignore mentions of rspack; this PR actually runs webpack but wrongly labels it rspack; I'm fixing this separately.

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.

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/...'

3 participants