Skip to content

Commit

Permalink
fs: throw mkdirSync errors in JS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung committed Feb 27, 2018
1 parent 46164ba commit 77b42e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,9 @@ fs.mkdirSync = function(path, mode) {
validatePath(path);
mode = modeNum(mode, 0o777);
validateUint32(mode, 'mode');
return binding.mkdir(pathModule.toNamespacedPath(path), mode);
const ctx = { path };
binding.mkdir(pathModule.toNamespacedPath(path), mode, undefined, ctx);
handleErrorFromBinding(ctx);
};

fs.readdir = function(path, options, callback) {
Expand Down
16 changes: 10 additions & 6 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1025,20 +1025,24 @@ static void RMDir(const FunctionCallbackInfo<Value>& args) {
static void MKDir(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK_GE(args.Length(), 2);
CHECK(args[1]->IsInt32());
const int argc = args.Length();
CHECK_GE(argc, 3);

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

int mode = static_cast<int>(args[1]->Int32Value());
CHECK(args[1]->IsInt32());
const int mode = args[1].As<Int32>()->Value();

FSReqBase* req_wrap = GetReqWrap(env, args[2]);
if (req_wrap != nullptr) {
if (req_wrap != nullptr) { // mkdir(path, mode, req)
AsyncCall(env, req_wrap, args, "mkdir", UTF8, AfterNoArgs,
uv_fs_mkdir, *path, mode);
} else {
SYNC_CALL(mkdir, *path, *path, mode)
} else { // mkdir(path, mode, undefined, ctx)
CHECK_EQ(argc, 4);
fs_req_wrap req_wrap;
SyncCall(env, args[3], &req_wrap, "mkdir",
uv_fs_mkdir, *path, mode);
}
}

Expand Down

0 comments on commit 77b42e3

Please sign in to comment.