Skip to content

fs: fix do_not_throw_error argument index in sync fstat - #66637

Open
daniellockyer wants to merge 1 commit into
nodejs:mainfrom
daniellockyer:fs-fstat-sync-arg-index
Open

daniellockyer wants to merge 1 commit into
nodejs:mainfrom
daniellockyer:fs-fstat-sync-arg-index

Conversation

@daniellockyer

Copy link
Copy Markdown

The synchronous branch of the fstat binding read its do_not_throw_error flag from args[2], which is always undefined on that branch, so the flag was ignored and the binding always threw.

Read the flag from args[3] as documented, and restore tryStatSync() to closing the file descriptor it owns before re-throwing the fstat error, which was its behavior before the flag was introduced.

Refs: #49868
Assisted-by: MiniMax M3.1 Flash Preview + Opus 5.5

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

The synchronous branch of the fstat binding read its
do_not_throw_error flag from args[2], which is always undefined on
that branch, so the flag was ignored and the binding always threw.

Read the flag from args[3] as documented, and restore tryStatSync()
to closing the file descriptor it owns before rethrowing the fstat
error, which was its behaviour before the flag was introduced.

Refs: nodejs#49868
Assisted-by: MiniMax M3.1 Flash Preview + Opus 5.5
Signed-off-by: Daniel Lockyer <hi@daniellockyer.com>
@daniellockyer
daniellockyer force-pushed the fs-fstat-sync-arg-index branch from 2ea782d to 593b5bd Compare October 10, 2026 07:09
Comment thread lib/fs.js
stats = binding.fstat(fd, false, undefined, false);
threw = false;
} finally {
if (threw && !isUserFd) fs.closeSync(fd);
}

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.

Can you explain why we're switching shouldNotThrow from true to false and adding try/catch? The C++ fix seems unambiguously correct, but the motivation for the corresponding JS changes isn't really explained anywhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. 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.

3 participants