Skip to content

fs.rmSync returns wrong error code for not empty directory #57095

Closed

Description

@koplas

Version

v23.7.0

Platform

Darwin redacted 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:22:58 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8132 arm64

Subsystem

No response

What steps will reproduce the bug?

Call fs.rmSync on a not empty directory.

How often does it reproduce? Is there a required condition?

The not empty directory error must occur.

What is the expected behavior? Why is that the expected behavior?

Get the result code of ENOTEMPTY.

What do you see instead?

Get the result code of EACCES.

Additional information

The relevant line that returns the wrong error code:

node/src/node_file.cc

Lines 1706 to 1708 in 69fdce2

} else if (error == std::errc::directory_not_empty) {
std::string message = "Directory not empty: " + file_path_str;
return env->ThrowErrnoException(EACCES, "rm", message.c_str(), path_c_str);

A list of constants and their error codes: https://en.cppreference.com/w/cpp/error/errc.

Activity

  1. added
    fs
    on Feb 24, 2025
  2. added a commit that references this issue on Feb 25, 2025
  3. added a commit that references this issue on Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions