Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename FSError to UVException and move to node.cc

  • Loading branch information...
commit 823a443321360e089e9c6d169a6cc116e3fb50b2 1 parent 1ad30a2
@piscisaureus piscisaureus authored Bert Belder committed
Showing with 88 additions and 87 deletions.
  1. +76 −0 src/node.cc
  2. +6 −0 src/node.h
  3. +6 −87 src/node_file.cc
View
76 src/node.cc
@@ -800,6 +800,82 @@ Local<Value> ErrnoException(int errorno,
}
+static const char* get_uv_errno_string(int errorno) {
+ uv_err_t err;
+ memset(&err, 0, sizeof err);
+ err.code = (uv_err_code)errorno;
+ return uv_err_name(err);
+}
+
+
+static const char* get_uv_errno_message(int errorno) {
+ uv_err_t err;
+ memset(&err, 0, sizeof err);
+ err.code = (uv_err_code)errorno;
+ return uv_strerror(err);
+}
+
+
+// hack alert! copy of ErrnoException, tuned for uv errors
+Local<Value> UVException(int errorno,
+ const char *syscall,
+ const char *msg,
+ const char *path) {
+ static Persistent<String> syscall_symbol;
+ static Persistent<String> errpath_symbol;
+ static Persistent<String> code_symbol;
+
+ if (syscall_symbol.IsEmpty()) {
+ syscall_symbol = NODE_PSYMBOL("syscall");
+ errno_symbol = NODE_PSYMBOL("errno");
+ errpath_symbol = NODE_PSYMBOL("path");
+ code_symbol = NODE_PSYMBOL("code");
+ }
+
+ if (!msg || !msg[0])
+ msg = get_uv_errno_message(errorno);
+
+ Local<String> estring = String::NewSymbol(errno_string(errorno));
+ Local<String> message = String::NewSymbol(msg);
+ Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
+ Local<String> cons2 = String::Concat(cons1, message);
+
+ Local<Value> e;
+
+ Local<String> path_str;
+
+ if (path) {
+#ifdef _WIN32
+ if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) {
+ path_str = String::Concat(String::New("\\\\"), String::New(path + 8));
+ } else if (strncmp(path, "\\\\?\\", 4) == 0) {
+ path_str = String::New(path + 4);
+ } else {
+ path_str = String::New(path);
+ }
+#else
+ path_str = String::New(path);
+#endif
+
+ Local<String> cons3 = String::Concat(cons2, String::NewSymbol(" '"));
+ Local<String> cons4 = String::Concat(cons3, path_str);
+ Local<String> cons5 = String::Concat(cons4, String::NewSymbol("'"));
+ e = Exception::Error(cons5);
+ } else {
+ e = Exception::Error(cons2);
+ }
+
+ Local<Object> obj = e->ToObject();
+
+ // TODO errno should probably go
+ obj->Set(errno_symbol, Integer::New(errorno));
+ obj->Set(code_symbol, estring);
+ if (path) obj->Set(errpath_symbol, path_str);
+ if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
+ return e;
+}
+
+
#ifdef _WIN32
Local<Value> WinapiErrnoException(int errorno,
const char* syscall,
View
6 src/node.h
@@ -192,6 +192,12 @@ NODE_EXTERN v8::Local<v8::Value> ErrnoException(int errorno,
const char *syscall = NULL,
const char *msg = "",
const char *path = NULL);
+
+NODE_EXTERN v8::Local<v8::Value> UVException(int errorno,
+ const char *syscall = NULL,
+ const char *msg = NULL,
+ const char *path = NULL);
+
#ifdef _WIN32
NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(int errorno,
const char *syscall = NULL, const char *msg = "",
View
93 src/node_file.cc
@@ -56,11 +56,6 @@ static Persistent<String> errno_symbol;
static Persistent<String> buf_symbol;
static Persistent<String> oncomplete_sym;
-Local<Value> FSError(int errorno,
- const char *syscall = NULL,
- const char *msg = NULL,
- const char *path = NULL);
-
#ifdef _LARGEFILE_SOURCE
static inline int IsInt64(double x) {
@@ -91,12 +86,12 @@ static void After(uv_fs_t *req) {
// If the request doesn't have a path parameter set.
if (!req->path) {
- argv[0] = FSError(req->errorno);
+ argv[0] = UVException(req->errorno);
} else {
- argv[0] = FSError(req->errorno,
- NULL,
- NULL,
- static_cast<const char*>(req->path));
+ argv[0] = UVException(req->errorno,
+ NULL,
+ NULL,
+ static_cast<const char*>(req->path));
}
} else {
// error value is empty or null for non-error.
@@ -210,82 +205,6 @@ struct fs_req_wrap {
};
-const char* errno_string(int errorno) {
- uv_err_t err;
- memset(&err, 0, sizeof err);
- err.code = (uv_err_code)errorno;
- return uv_err_name(err);
-}
-
-
-const char* errno_message(int errorno) {
- uv_err_t err;
- memset(&err, 0, sizeof err);
- err.code = (uv_err_code)errorno;
- return uv_strerror(err);
-}
-
-
-// hack alert! copy of ErrnoException in node.cc, tuned for uv errors
-Local<Value> FSError(int errorno,
- const char *syscall,
- const char *msg,
- const char *path) {
- static Persistent<String> syscall_symbol;
- static Persistent<String> errpath_symbol;
- static Persistent<String> code_symbol;
-
- if (syscall_symbol.IsEmpty()) {
- syscall_symbol = NODE_PSYMBOL("syscall");
- errno_symbol = NODE_PSYMBOL("errno");
- errpath_symbol = NODE_PSYMBOL("path");
- code_symbol = NODE_PSYMBOL("code");
- }
-
- if (!msg || !msg[0])
- msg = errno_message(errorno);
-
- Local<String> estring = String::NewSymbol(errno_string(errorno));
- Local<String> message = String::NewSymbol(msg);
- Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
- Local<String> cons2 = String::Concat(cons1, message);
-
- Local<Value> e;
-
- Local<String> path_str;
-
- if (path) {
-#ifdef _WIN32
- if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) {
- path_str = String::Concat(String::New("\\\\"), String::New(path + 8));
- } else if (strncmp(path, "\\\\?\\", 4) == 0) {
- path_str = String::New(path + 4);
- } else {
- path_str = String::New(path);
- }
-#else
- path_str = String::New(path);
-#endif
-
- Local<String> cons3 = String::Concat(cons2, String::NewSymbol(" '"));
- Local<String> cons4 = String::Concat(cons3, path_str);
- Local<String> cons5 = String::Concat(cons4, String::NewSymbol("'"));
- e = Exception::Error(cons5);
- } else {
- e = Exception::Error(cons2);
- }
-
- Local<Object> obj = e->ToObject();
-
- // TODO errno should probably go
- obj->Set(errno_symbol, Integer::New(errorno));
- obj->Set(code_symbol, estring);
- if (path) obj->Set(errpath_symbol, path_str);
- if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
- return e;
-}
-
-
#define ASYNC_CALL(func, callback, ...) \
FSReqWrap* req_wrap = new FSReqWrap(); \
int r = uv_fs_##func(uv_default_loop(), &req_wrap->req_, \
@@ -300,7 +219,7 @@ Local<Value> FSError(int errorno,
int result = uv_fs_##func(uv_default_loop(), &req_wrap.req, __VA_ARGS__, NULL); \
if (result < 0) { \
int code = uv_last_error(uv_default_loop()).code; \
- return ThrowException(FSError(code, #func, "", path)); \
+ return ThrowException(UVException(code, #func, "", path)); \
}
#define SYNC_REQ req_wrap.req
Please sign in to comment.
Something went wrong with that request. Please try again.