Skip to content

Commit

Permalink
fs: report source and destination files in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
caitp committed Jan 12, 2015
1 parent d51efd0 commit 68d6a12
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <errno.h>
#include <limits.h>

#include <string>

#if defined(__MINGW32__) || defined(_MSC_VER)
# include <io.h>
#endif
Expand Down Expand Up @@ -122,6 +124,18 @@ static inline bool IsInt64(double x) {
}


static std::string srcdestError(const char *syscall, const char *source,
const char *destination) {
std::string errmsg(syscall);
return errmsg.
append(" '").
append(source).
append("' -> '").
append(destination).
append("'");
}


static void After(uv_fs_t *req) {
FSReqWrap* req_wrap = static_cast<FSReqWrap*>(req->data);
CHECK_EQ(&req_wrap->req_, req);
Expand All @@ -142,14 +156,10 @@ static void After(uv_fs_t *req) {
// If the request doesn't have a path parameter set.
if (req->path == nullptr) {
argv[0] = UVException(req->result, nullptr, req_wrap->syscall());
} else if ((req->result == UV_EEXIST ||
req->result == UV_ENOTEMPTY ||
req->result == UV_EPERM) &&
req_wrap->dest_len() > 0) {
argv[0] = UVException(req->result,
nullptr,
req_wrap->syscall(),
req_wrap->dest());
} else if (req_wrap->dest_len() > 0) {
const char* syscall = req_wrap->syscall();
std::string errmsg = srcdestError(syscall, req->path, req_wrap->dest());
argv[0] = UVException(req->result, nullptr, errmsg.c_str());
} else {
argv[0] = UVException(req->result,
nullptr,
Expand Down Expand Up @@ -300,11 +310,9 @@ struct fs_req_wrap {
__VA_ARGS__, \
nullptr); \
if (err < 0) { \
if (dest != nullptr && \
(err == UV_EEXIST || \
err == UV_ENOTEMPTY || \
err == UV_EPERM)) { \
return env->ThrowUVException(err, #func, "", dest); \
if (dest != nullptr) { \
std::string errmsg = srcdestError(#func, path, dest); \
return env->ThrowUVException(err, nullptr, errmsg.c_str()); \
} else { \
return env->ThrowUVException(err, #func, "", path); \
} \
Expand Down

0 comments on commit 68d6a12

Please sign in to comment.