summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-01-24 06:53:47 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-02-01 15:52:11 +0800
commit32bf0f6c5b3648a487c3fc56d0830de2ceeb60a5 (patch)
tree37aca3d7e1ba04d747b13cfcb6a0054de5e0f1e5 /lib
parentbf6ce47259ebfe9f6349c223cc1735726aee062d (diff)
downloadandroid-node-v8-32bf0f6c5b3648a487c3fc56d0830de2ceeb60a5.tar.gz
android-node-v8-32bf0f6c5b3648a487c3fc56d0830de2ceeb60a5.tar.bz2
android-node-v8-32bf0f6c5b3648a487c3fc56d0830de2ceeb60a5.zip
fs: throw errors from fs.symlinkSync in JS
PR-URL: https://github.com/nodejs/node/pull/18348 Refs: https://github.com/nodejs/node/issues/18106 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 0103500f0b..c75a8501b6 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1220,6 +1220,7 @@ fs.symlink = function(target, path, type_, callback_) {
const flags = stringToSymlinkType(type);
const req = new FSReqWrap();
req.oncomplete = callback;
+
binding.symlink(preprocessSymlinkDestination(target, type, path),
pathModule.toNamespacedPath(path), flags, req);
};
@@ -1234,8 +1235,19 @@ fs.symlinkSync = function(target, path, type) {
validatePath(target, 'target');
validatePath(path);
const flags = stringToSymlinkType(type);
- return binding.symlink(preprocessSymlinkDestination(target, type, path),
- pathModule.toNamespacedPath(path), flags);
+
+ const ctx = { path: target, dest: path };
+ binding.symlink(preprocessSymlinkDestination(target, type, path),
+ pathModule.toNamespacedPath(path), flags, undefined, ctx);
+
+ if (ctx.errno !== undefined) {
+ throw new errors.uvException(ctx);
+ } else if (ctx.error) {
+ // TODO(joyeecheung): this is an encoding error usually caused by memory
+ // problems. We need to figure out proper error code(s) for this.
+ Error.captureStackTrace(ctx.error);
+ throw ctx.error;
+ }
};
fs.link = function(existingPath, newPath, callback) {