Skip to content

Commit 8b97249

Browse files
yorkiejasnell
authored andcommitted
fs: fix the error report on fs.link(Sync)
As the Node.js documentation specified: > fs.link(srcpath, dstpath, callback) But when we run: ```js > fs.link() ``` We will get the below: ```js TypeError: dest path must be a string at TypeError (native) at Object.fs.link (fs.js:915:11) at repl:1:4 ``` Just correct the message of relevant 2 errors in this PR :-) PR-URL: #3917 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 9472a0c commit 8b97249

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/node_file.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,13 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
615615

616616
int len = args.Length();
617617
if (len < 1)
618-
return TYPE_ERROR("dest path required");
619-
if (len < 2)
620618
return TYPE_ERROR("src path required");
619+
if (len < 2)
620+
return TYPE_ERROR("dest path required");
621621
if (!args[0]->IsString())
622-
return TYPE_ERROR("dest path must be a string");
623-
if (!args[1]->IsString())
624622
return TYPE_ERROR("src path must be a string");
623+
if (!args[1]->IsString())
624+
return TYPE_ERROR("dest path must be a string");
625625

626626
node::Utf8Value orig_path(env->isolate(), args[0]);
627627
node::Utf8Value new_path(env->isolate(), args[1]);

test/parallel/test-fs-link.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@ const callback = function(err) {
1818
};
1919

2020
fs.link(srcPath, dstPath, common.mustCall(callback));
21+
22+
// test error outputs
23+
24+
assert.throws(
25+
function() {
26+
fs.link();
27+
},
28+
/src path/
29+
);
30+
31+
assert.throws(
32+
function() {
33+
fs.link('abc');
34+
},
35+
/dest path/
36+
);

0 commit comments

Comments
 (0)