Skip to content

Instantly share code, notes, and snippets.

@BridgeAR
Last active April 26, 2018 15:47
Show Gist options
  • Save BridgeAR/f546d3e8fe3e4f4caabc2554ad7a3811 to your computer and use it in GitHub Desktop.
Save BridgeAR/f546d3e8fe3e4f4caabc2554ad7a3811 to your computer and use it in GitHub Desktop.
Add path to error messages
diff --git a/src/node_file.cc b/src/node_file.cc
index 89c53afc5b..f81433e53c 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -612,7 +612,7 @@ template <typename Func, typename... Args>
 inline FSReqBase* AsyncDestCall(Environment* env,
     FSReqBase* req_wrap,
     const FunctionCallbackInfo<Value>& args,
-    const char* syscall, const char* dest, size_t len,
+    const char* syscall, const char* path, const char* dest, size_t len,
     enum encoding enc, uv_fs_cb after, Func fn, Args... fn_args) {
   CHECK_NE(req_wrap, nullptr);
   req_wrap->Init(syscall, dest, len, enc);
@@ -621,7 +621,7 @@ inline FSReqBase* AsyncDestCall(Environment* env,
   if (err < 0) {
     uv_fs_t* uv_req = req_wrap->req();
     uv_req->result = err;
-    uv_req->path = nullptr;
+    uv_req->path = path;
     after(uv_req);  // after may delete req_wrap if there is an error
     req_wrap = nullptr;
   } else {
@@ -639,7 +639,7 @@ inline FSReqBase* AsyncCall(Environment* env,
     const char* syscall, enum encoding enc,
     uv_fs_cb after, Func fn, Args... fn_args) {
   return AsyncDestCall(env, req_wrap, args,
-                       syscall, nullptr, 0, enc,
+                       syscall, nullptr, nullptr, 0, enc,
                        after, fn, fn_args...);
 }
 
@@ -916,8 +916,9 @@ static void Symlink(const FunctionCallbackInfo<Value>& args) {
 
   FSReqBase* req_wrap_async = GetReqWrap(env, args[3]);
   if (req_wrap_async != nullptr) {  // symlink(target, path, flags, req)
-    AsyncDestCall(env, req_wrap_async, args, "symlink", *path, path.length(),
-                  UTF8, AfterNoArgs, uv_fs_symlink, *target, *path, flags);
+    AsyncDestCall(env, req_wrap_async, args, "symlink", *target, *path,
+                  path.length(), UTF8, AfterNoArgs, uv_fs_symlink,
+                  *target, *path, flags);
   } else {  // symlink(target, path, flags, undefinec, ctx)
     CHECK_EQ(argc, 5);
     FSReqWrapSync req_wrap_sync;
@@ -942,8 +943,9 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
 
   FSReqBase* req_wrap_async = GetReqWrap(env, args[2]);
   if (req_wrap_async != nullptr) {  // link(src, dest, req)
-    AsyncDestCall(env, req_wrap_async, args, "link", *dest, dest.length(), UTF8,
-                  AfterNoArgs, uv_fs_link, *src, *dest);
+    AsyncDestCall(env, req_wrap_async, args, "link", *src, *dest,
+                  dest.length(), UTF8, AfterNoArgs, uv_fs_link,
+                  *src, *dest);
   } else {  // link(src, dest)
     CHECK_EQ(argc, 4);
     FSReqWrapSync req_wrap_sync;
@@ -1009,7 +1011,7 @@ static void Rename(const FunctionCallbackInfo<Value>& args) {
 
   FSReqBase* req_wrap_async = GetReqWrap(env, args[2]);
   if (req_wrap_async != nullptr) {
-    AsyncDestCall(env, req_wrap_async, args, "rename", *new_path,
+    AsyncDestCall(env, req_wrap_async, args, "rename", *old_path, *new_path,
                   new_path.length(), UTF8, AfterNoArgs, uv_fs_rename,
                   *old_path, *new_path);
   } else {
@@ -1370,7 +1372,7 @@ static void CopyFile(const FunctionCallbackInfo<Value>& args) {
 
   FSReqBase* req_wrap_async = GetReqWrap(env, args[3]);
   if (req_wrap_async != nullptr) {  // copyFile(src, dest, flags, req)
-    AsyncDestCall(env, req_wrap_async, args, "copyfile",
+    AsyncDestCall(env, req_wrap_async, args, "copyfile", *src,
                   *dest, dest.length(), UTF8, AfterNoArgs,
                   uv_fs_copyfile, *src, *dest, flags);
   } else {  // copyFile(src, dest, flags, undefined, ctx)
   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment