Skip to content

fs: fix rmSync error messages for non-ASCII paths - #61233

Merged
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
Yeaseen:fix-additional-error-message-rmsync
Aug 27, 2026
Merged

fs: fix rmSync error messages for non-ASCII paths#61233
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
Yeaseen:fix-additional-error-message-rmsync

Conversation

@Yeaseen

@Yeaseen Yeaseen commented Jan 1, 2026

Copy link
Copy Markdown
Contributor

This PR fixes incorrect and inconsistent error messages produced by fs.rmSync when deletion fails, especially for directories containing non-ASCII characters. The issue affected Linux and Windows differently but shared the same root cause: paths were embedded into custom error messages while also being passed separately to ThrowErrnoException.

1. Duplicate paths in error messages (Linux, ASCII paths)

fs.rmSync constructed messages like:

std::string message = "Permission denied: " + file_path_str;
env->ThrowErrnoException(err, "rm", message.c_str(), path_c_str);

Because ThrowErrnoException automatically appends the path, this resulted in duplicated paths when directory names were ASCII-only:

err.path: /tmp/_dir_0
err.message: EACCES, Permission denied: /tmp/_dir_0 '/tmp/_dir_0'

2. Corrupted paths for non-ASCII directory names (Linux)

When the directory name contained non-ASCII characters, embedding the path into the message caused UTF-8 bytes to be misinterpreted.

Example:

err.path: /tmp/ι€Ÿι€Ÿι€Ÿ_dir
err.message: EACCES, Permission denied: '/tmp/Γ©ι€Ÿι€Ÿ_dir'

Here, the first byte of the UTF-8 sequence was interpreted as a Latin-1 character (Γ©), corrupting the path shown in the error message.

3. Inconsistent Windows paths (?\ prefix)

On Windows, err.path could expose raw extended-length paths prefixed with \\?\\, because the platform-specific normalization logic (StringFromPath) was not applied when constructing ErrnoException.
Example:

err.path: \\?\\C:\\temp\\ι€Ÿι€Ÿι€Ÿ_dir

This is inconsistent with other fs APIs used in src/api/exceptions, which strip the prefix before exposing paths to JavaScript.

This PR fixes the issue by:

  • Removing path concatenation from custom error messages
  • Passing the path only via the path argument to ThrowErrnoException
  • Relying on Node’s standard error formatting to attach paths safely
  • Applying StringFromPath in src/api/exceptions for Windows so err.path is normalized correctly

A new test has been added: test-fs-rmSync-special-char-additional-error.js to verify that:

  • fs.rmSync reports the correct error code
  • err.path preserves non-ASCII directory names
  • err.message includes the correct path
  • No path corruption or duplication occurs

@joyeecheung @anonrig Please review this when you are available.

@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 the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jan 1, 2026
@codecov

codecov Bot commented Jan 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
βœ… Project coverage is 90.14%. Comparing base (f96dccc) to head (de31cdd).
⚠️ Report is 52 commits behind head on main.

Files with missing lines Patch % Lines
src/node_file.cc 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61233      +/-   ##
==========================================
- Coverage   90.15%   90.14%   -0.02%     
==========================================
  Files         751      751              
  Lines      253443   253468      +25     
  Branches    47729    47737       +8     
==========================================
- Hits       228496   228493       -3     
- Misses      16201    16253      +52     
+ Partials     8746     8722      -24     
Files with missing lines Coverage Ξ”
src/api/exceptions.cc 94.38% <100.00%> (+0.19%) ⬆️
src/node_file.cc 73.97% <40.00%> (+0.10%) ⬆️

... and 44 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.

@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch 2 times, most recently from a836c7f to a68d666 Compare January 1, 2026 11:21
@LucasmDjuiw

LucasmDjuiw commented Jan 27, 2026

Copy link
Copy Markdown

8,5/10.

Ce document est clair, techniquement précis et facile à comprendre. Sa structure est fluide et explique le problème et sa solution sans détails superflus. Pour atteindre 9 ou 10, il faudrait simplifier légèrement quelques Casino Frumzi phrases ou ajouter une courte phrase de conclusion soulignant l'impact pour les utilisateurs ou les responsables de la maintenance.

@joyeecheung

Copy link
Copy Markdown
Member

Code LGTM, though I am a bit skeptical about the tests - it may not fare well on Windows in the CI or in people's local machines to change the permission this way. Can we use other safer error paths to check it instead? Perhaps the directory not empty one?

@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch from a68d666 to 4bc9b95 Compare February 18, 2026 11:20
@Yeaseen

Yeaseen commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

@joyeecheung thanks for the feedback. I agree. I updated the test case for hitting NOT A DIRECTORY error. Let's see if it passes CI.

@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch from 4bc9b95 to 91a7aad Compare February 18, 2026 11:34
@Yeaseen

Yeaseen commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

@joyeecheung looks good so far. The failing test on mac is unrelated to my changes. I appreciate a rerun. Thanks.

@Yeaseen

Yeaseen commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

@joyeecheung CI is green now β€” would appreciate your review.

Comment thread src/api/exceptions.cc Outdated
@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch from 91a7aad to d1368b0 Compare February 18, 2026 20:58
Comment thread src/api/exceptions.cc Outdated
Comment thread src/api/exceptions.cc Outdated
@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch from d1368b0 to ab5dbcc Compare February 23, 2026 05:06
@Yeaseen

Yeaseen commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

@joyeecheung @anonrig @jazelly Please review this.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

@github-actions github-actions Bot added the stale label Jul 28, 2026
@Yeaseen

Yeaseen commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

I am just marking this as bugs in rmSync error messages. If anybody thinks it's worth fixing, I'll be happy to update this PR.

@github-actions github-actions Bot removed the stale label Jul 31, 2026
@trivikr

trivikr commented Aug 23, 2026

Copy link
Copy Markdown
Member

This PR needs a rebase.

@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch 2 times, most recently from 9bf892d to ec422e5 Compare August 24, 2026 03:20
Comment thread src/node_file.cc Outdated
Comment thread test/parallel/test-fs-rmSync-special-char-additional-error.js Outdated
fs.rmSync previously embedded paths directly into
custom error messages while also passing the path
to ThrowErrnoException.

This caused duplicated paths for ASCII names and
corrupted paths for non-ASCII directory names on
Linux, and inconsistent path formatting on Windows.

Remove path concatenation from custom messages and
rely on ThrowErrnoException to attach the path safely.
Add a test to cover non-ASCII directory names.

Signed-off-by: Yeaseen <yeaseen.arafat96@gmail.com>
@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch from ec422e5 to e0c7ce7 Compare August 24, 2026 04:45
Signed-off-by: Yeaseen <yeaseen.arafat96@gmail.com>
Signed-off-by: Yeaseen <yeaseen.arafat96@gmail.com>
@Yeaseen
Yeaseen force-pushed the fix-additional-error-message-rmsync branch from e0c7ce7 to de31cdd Compare August 24, 2026 06:00
@trivikr trivikr added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no outstanding review comments, and a CI started. labels Aug 24, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 24, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 26, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Aug 26, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

This pull request has multiple commits, but no landing policy was selected.

Add commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. to land it as one commit, or commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. to land the commits separately.

The pull request was removed from the Commit Queue and labeled commit-queue-failed An error occurred while landing this pull request using GitHub Actions. . After resolving the failure, remove that label and add commit-queue Add this label to land a pull request using GitHub Actions. to retry.

Full Commit Queue output
- Loading data for nodejs/node/pull/61233
βœ”  Done loading data for nodejs/node/pull/61233
----------------------------------- PR info ------------------------------------
Title      fs: fix rmSync error messages for non-ASCII paths (#61233)
Author     Yeaseen <u1464680@umail.utah.edu> (@Yeaseen)
Branch     Yeaseen:fix-additional-error-message-rmsync -> nodejs:main
Labels     c++, fs, author ready, needs-ci, commit-queue
Commits    3
 - fs: fix rmSync error messages for non-ASCII paths
 - test: add rmSync path duplication coverage
 - src/api: use std::string_view in exceptions StringFromPath
Committers 1
 - Yeaseen <yeaseen.arafat96@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61233
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/61233
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
--------------------------------------------------------------------------------
   β„Ή  This PR was created on Thu, 01 Jan 2026 08:19:08 GMT
   βœ”  Approvals: 2
   βœ”  - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/61233#pullrequestreview-3842014483
   βœ”  - Trivikram Kamat (@trivikr): https://github.com/nodejs/node/pull/61233#pullrequestreview-5008883829
   βœ”  Last GitHub CI successful
   β„Ή  Last Full PR CI on 2026-08-26T00:06:23Z: https://ci.nodejs.org/job/node-test-pull-request/76487/
- Querying data for job/node-test-pull-request/76487/
βœ”  Build data downloaded
   βœ”  Last Jenkins CI successful
--------------------------------------------------------------------------------
   βœ”  No git cherry-pick in progress
   βœ”  No git am in progress
   βœ”  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
   af7f91d395..76bb3f7396  main       -> origin/main
βœ”  origin/main is now up-to-date
main is out of sync with origin/main. Mismatched commits:
 - 2cac6df1fa tools: enable concurrency for eslint
 - 76bb3f7396 tools: enable concurrency for eslint
--------------------------------------------------------------------------------
HEAD is now at 76bb3f7396 tools: enable concurrency for eslint
   βœ”  Reset to origin/main
- Downloading patch for 61233
From https://github.com/nodejs/node
 * branch                  refs/pull/61233/merge -> FETCH_HEAD
βœ”  Fetched commits as 49c87ef145e1..de31cdde71be
--------------------------------------------------------------------------------
Auto-merging src/node_file.cc
[main f6f137acb0] fs: fix rmSync error messages for non-ASCII paths
 Author: Yeaseen <yeaseen.arafat96@gmail.com>
 Date: Wed Dec 31 18:59:32 2025 -0700
 3 files changed, 72 insertions(+), 22 deletions(-)
 create mode 100644 test/parallel/test-fs-rmSync-special-char-additional-error.js
[main d7cb4370ed] test: add rmSync path duplication coverage
 Author: Yeaseen <yeaseen.arafat96@gmail.com>
 Date: Wed Feb 18 04:19:43 2026 -0700
 1 file changed, 39 insertions(+), 21 deletions(-)
[main e81d066f15] src/api: use std::string_view in exceptions StringFromPath
 Author: Yeaseen <yeaseen.arafat96@gmail.com>
 Date: Wed Feb 18 13:57:57 2026 -0700
 1 file changed, 33 insertions(+), 12 deletions(-)
   βœ”  Patches applied
There are 3 commits in the PR. Attempting autorebase.
(node:2227) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Rebasing (2/6)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fs: fix rmSync error messages for non-ASCII paths

fs.rmSync previously embedded paths directly into
custom error messages while also passing the path
to ThrowErrnoException.

This caused duplicated paths for ASCII names and
corrupted paths for non-ASCII directory names on
Linux, and inconsistent path formatting on Windows.

Remove path concatenation from custom messages and
rely on ThrowErrnoException to attach the path safely.
Add a test to cover non-ASCII directory names.

Signed-off-by: Yeaseen <yeaseen.arafat96@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61233
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD ed3ca6276f] fs: fix rmSync error messages for non-ASCII paths
 Author: Yeaseen <yeaseen.arafat96@gmail.com>
 Date: Wed Dec 31 18:59:32 2025 -0700
 3 files changed, 72 insertions(+), 22 deletions(-)
 create mode 100644 test/parallel/test-fs-rmSync-special-char-additional-error.js
Rebasing (3/6)
Rebasing (4/6)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
test: add rmSync path duplication coverage

Signed-off-by: Yeaseen <yeaseen.arafat96@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61233
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD 330b3c174e] test: add rmSync path duplication coverage
 Author: Yeaseen <yeaseen.arafat96@gmail.com>
 Date: Wed Feb 18 04:19:43 2026 -0700
 1 file changed, 39 insertions(+), 21 deletions(-)
Rebasing (5/6)
Rebasing (6/6)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
src/api: use std::string_view in exceptions StringFromPath

Signed-off-by: Yeaseen <yeaseen.arafat96@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61233
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD 0494e54484] src/api: use std::string_view in exceptions StringFromPath
 Author: Yeaseen <yeaseen.arafat96@gmail.com>
 Date: Wed Feb 18 13:57:57 2026 -0700
 1 file changed, 33 insertions(+), 12 deletions(-)
Successfully rebased and updated refs/heads/main.
--------------------------------------------------------------------------------
   β„Ή  Add `commit-queue-squash` label to land the PR as one commit, or `commit-queue-rebase` to land as separate commits.

View workflow run

@trivikr trivikr added commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Aug 27, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 37aeecc into nodejs:main Aug 27, 2026
88 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 37aeecc

@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants