Skip to content

Commit b1c6ecb

Browse files
committed
fs: fix misplaced errors in fs.symlinkSync
The ctx.error is supposed to be handled in fs.readlinkSync, but was handled in fs.symlinkSync by mistake. Also fix the error number check in readlink to be consistent with SYNC_CALL. PR-URL: #18548 Refs: #18348 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent e9b5b4f commit b1c6ecb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/fs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,11 @@ fs.readlinkSync = function(path, options) {
11611161
options.encoding, undefined, ctx);
11621162
if (ctx.errno !== undefined) {
11631163
throw errors.uvException(ctx);
1164+
} else if (ctx.error) {
1165+
// TODO(joyeecheung): this is an encoding error usually caused by memory
1166+
// problems. We need to figure out proper error code(s) for this.
1167+
Error.captureStackTrace(ctx.error);
1168+
throw ctx.error;
11641169
}
11651170
return result;
11661171
};
@@ -1232,11 +1237,6 @@ fs.symlinkSync = function(target, path, type) {
12321237

12331238
if (ctx.errno !== undefined) {
12341239
throw errors.uvException(ctx);
1235-
} else if (ctx.error) {
1236-
// TODO(joyeecheung): this is an encoding error usually caused by memory
1237-
// problems. We need to figure out proper error code(s) for this.
1238-
Error.captureStackTrace(ctx.error);
1239-
throw ctx.error;
12401240
}
12411241
};
12421242

src/node_file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
886886
fs_req_wrap req;
887887
int err = SyncCall(env, args[3], &req, "readlink",
888888
uv_fs_readlink, *path);
889-
if (err) {
889+
if (err < 0) {
890890
return; // syscall failed, no need to continue, error info is in ctx
891891
}
892892
const char* link_path = static_cast<const char*>(req.req.ptr);

0 commit comments

Comments
 (0)