Skip to content

fs: restore stack traces of fs/promises stat permission errors - #67525

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
vedchaudhari:fs-promises-stat-stack
Nov 19, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
vedchaudhari:fs-promises-stat-stack

Conversation

@vedchaudhari

Copy link
Copy Markdown
Contributor

Since #63143, errors from fs.promises.stat() have no stack frames when the permission model denies access. This affects v26.8.0+; v26.7.0, v24.x and v22.x aren't affected.

# main
Error: Access to this API has been restricted. Use --allow-fs-read to manage permissions.

# this PR
Error: Access to this API has been restricted. Use --allow-fs-read to manage permissions.
    at async stat (node:internal/fs/promises:1912:18)
    at async checkConfig ([eval]:3:3)

The binding rejects a denied stat() right away, and raceWithSignal() returned that promise from an async function without awaiting it, so nothing was awaiting it yet when the stack was captured. This returns the promise as is when there's no signal, so stat() awaits it directly like before. With a signal, nothing changes. It's the same problem as the appendFile() case in #66757.

Added a case to the test from #66757; it fails on main and passes with this change. Tested on Windows x64.

cc @mertcanaltin @christianaurichzm

AI-assisted. I reproduced the bug and ran the tests myself.

Since stat() started going through raceWithSignal(), permission
errors from fsPromises.stat() have had no stack frames. The binding
rejects them right away, and raceWithSignal() returned that promise
from an async function without awaiting it, so nothing was awaiting
it yet when the stack was captured.

Return the promise as is when there is no signal, so stat() awaits
it directly again.

Refs: nodejs#63143
Signed-off-by: vedchaudhari <vedc2853@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 16, 2026
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.67%. Comparing base (d3c4048) to head (b5726c5).
⚠️ Report is 68 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67525      +/-   ##
==========================================
+ Coverage   90.66%   90.67%   +0.01%     
==========================================
  Files         799      799              
  Lines      280252   280318      +66     
  Branches    54121    54134      +13     
==========================================
+ Hits       254088   254182      +94     
+ Misses      16285    16243      -42     
- Partials     9879     9893      +14     
Files with missing lines Coverage Δ
lib/internal/fs/promises.js 91.79% <100.00%> (+0.01%) ⬆️

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@christianaurichzm christianaurichzm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@christianaurichzm christianaurichzm added author ready PRs with CI started, the required approvals, and no outstanding review comments. resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. labels Nov 18, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 19, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@christianaurichzm christianaurichzm added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
@nodejs-github-bot
nodejs-github-bot merged commit cdd0687 into nodejs:main Nov 19, 2026
83 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in cdd0687

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
aduh95 pushed a commit that referenced this pull request Nov 19, 2026
Since stat() started going through raceWithSignal(), permission
errors from fsPromises.stat() have had no stack frames. The binding
rejects them right away, and raceWithSignal() returned that promise
from an async function without awaiting it, so nothing was awaiting
it yet when the stack was captured.

Return the promise as is when there is no signal, so stat() awaits
it directly again.

Refs: #63143
Signed-off-by: vedchaudhari <vedc2853@gmail.com>
PR-URL: #67525
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants