Skip to content

Commit 46164ba

Browse files
committed
fs: throw rmdirSync errors in JS
PR-URL: #18871 Refs: #18106 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 29be1e5 commit 46164ba

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/fs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,9 @@ fs.rmdir = function(path, callback) {
748748
fs.rmdirSync = function(path) {
749749
path = getPathFromURL(path);
750750
validatePath(path);
751-
return binding.rmdir(pathModule.toNamespacedPath(path));
751+
const ctx = { path };
752+
binding.rmdir(pathModule.toNamespacedPath(path), undefined, ctx);
753+
handleErrorFromBinding(ctx);
752754
};
753755

754756
fs.fdatasync = function(fd, callback) {

src/node_file.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,17 +1004,21 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
10041004
static void RMDir(const FunctionCallbackInfo<Value>& args) {
10051005
Environment* env = Environment::GetCurrent(args);
10061006

1007-
CHECK_GE(args.Length(), 1);
1007+
const int argc = args.Length();
1008+
CHECK_GE(argc, 2);
10081009

10091010
BufferValue path(env->isolate(), args[0]);
10101011
CHECK_NE(*path, nullptr);
10111012

1012-
FSReqBase* req_wrap = GetReqWrap(env, args[1]);
1013+
FSReqBase* req_wrap = GetReqWrap(env, args[1]); // rmdir(path, req)
10131014
if (req_wrap != nullptr) {
10141015
AsyncCall(env, req_wrap, args, "rmdir", UTF8, AfterNoArgs,
10151016
uv_fs_rmdir, *path);
1016-
} else {
1017-
SYNC_CALL(rmdir, *path, *path)
1017+
} else { // rmdir(path, undefined, ctx)
1018+
CHECK_EQ(argc, 3);
1019+
fs_req_wrap req_wrap;
1020+
SyncCall(env, args[2], &req_wrap, "rmdir",
1021+
uv_fs_rmdir, *path);
10181022
}
10191023
}
10201024

0 commit comments

Comments
 (0)