diff --git a/src/node.cc b/src/node.cc index eb5c626e883..ee6a86cecce 100644 --- a/src/node.cc +++ b/src/node.cc @@ -50,6 +50,9 @@ namespace node { static Persistent process; +static Persistent errno_symbol; +static Persistent syscall_symbol; + static Persistent dev_symbol; static Persistent ino_symbol; static Persistent mode_symbol; @@ -278,6 +281,353 @@ static void EIODonePoll(void) { } +static inline const char *errno_string(int errorno) { +#define ERRNO_CASE(e) case e: return #e; + switch (errorno) { + +#ifdef EACCES + ERRNO_CASE(EACCES); +#endif + +#ifdef EADDRINUSE + ERRNO_CASE(EADDRINUSE); +#endif + +#ifdef EADDRNOTAVAIL + ERRNO_CASE(EADDRNOTAVAIL); +#endif + +#ifdef EAFNOSUPPORT + ERRNO_CASE(EAFNOSUPPORT); +#endif + +#ifdef EAGAIN + ERRNO_CASE(EAGAIN); +#else +# ifdef EWOULDBLOCK + ERRNO_CASE(EWOULDBLOCK); +# endif +#endif + +#ifdef EALREADY + ERRNO_CASE(EALREADY); +#endif + +#ifdef EBADF + ERRNO_CASE(EBADF); +#endif + +#ifdef EBADMSG + ERRNO_CASE(EBADMSG); +#endif + +#ifdef EBUSY + ERRNO_CASE(EBUSY); +#endif + +#ifdef ECANCELED + ERRNO_CASE(ECANCELED); +#endif + +#ifdef ECHILD + ERRNO_CASE(ECHILD); +#endif + +#ifdef ECONNABORTED + ERRNO_CASE(ECONNABORTED); +#endif + +#ifdef ECONNREFUSED + ERRNO_CASE(ECONNREFUSED); +#endif + +#ifdef ECONNRESET + ERRNO_CASE(ECONNRESET); +#endif + +#ifdef EDEADLK + ERRNO_CASE(EDEADLK); +#endif + +#ifdef EDESTADDRREQ + ERRNO_CASE(EDESTADDRREQ); +#endif + +#ifdef EDOM + ERRNO_CASE(EDOM); +#endif + +#ifdef EDQUOT + ERRNO_CASE(EDQUOT); +#endif + +#ifdef EEXIST + ERRNO_CASE(EEXIST); +#endif + +#ifdef EFAULT + ERRNO_CASE(EFAULT); +#endif + +#ifdef EFBIG + ERRNO_CASE(EFBIG); +#endif + +#ifdef EHOSTUNREACH + ERRNO_CASE(EHOSTUNREACH); +#endif + +#ifdef EIDRM + ERRNO_CASE(EIDRM); +#endif + +#ifdef EILSEQ + ERRNO_CASE(EILSEQ); +#endif + +#ifdef EINPROGRESS + ERRNO_CASE(EINPROGRESS); +#endif + +#ifdef EINTR + ERRNO_CASE(EINTR); +#endif + +#ifdef EINVAL + ERRNO_CASE(EINVAL); +#endif + +#ifdef EIO + ERRNO_CASE(EIO); +#endif + +#ifdef EISCONN + ERRNO_CASE(EISCONN); +#endif + +#ifdef EISDIR + ERRNO_CASE(EISDIR); +#endif + +#ifdef ELOOP + ERRNO_CASE(ELOOP); +#endif + +#ifdef EMFILE + ERRNO_CASE(EMFILE); +#endif + +#ifdef EMLINK + ERRNO_CASE(EMLINK); +#endif + +#ifdef EMSGSIZE + ERRNO_CASE(EMSGSIZE); +#endif + +#ifdef EMULTIHOP + ERRNO_CASE(EMULTIHOP); +#endif + +#ifdef ENAMETOOLONG + ERRNO_CASE(ENAMETOOLONG); +#endif + +#ifdef ENETDOWN + ERRNO_CASE(ENETDOWN); +#endif + +#ifdef ENETRESET + ERRNO_CASE(ENETRESET); +#endif + +#ifdef ENETUNREACH + ERRNO_CASE(ENETUNREACH); +#endif + +#ifdef ENFILE + ERRNO_CASE(ENFILE); +#endif + +#ifdef ENOBUFS + ERRNO_CASE(ENOBUFS); +#endif + +#ifdef ENODATA + ERRNO_CASE(ENODATA); +#endif + +#ifdef ENODEV + ERRNO_CASE(ENODEV); +#endif + +#ifdef ENOENT + ERRNO_CASE(ENOENT); +#endif + +#ifdef ENOEXEC + ERRNO_CASE(ENOEXEC); +#endif + +#ifdef ENOLCK + ERRNO_CASE(ENOLCK); +#endif + +#ifdef ENOLINK + ERRNO_CASE(ENOLINK); +#endif + +#ifdef ENOMEM + ERRNO_CASE(ENOMEM); +#endif + +#ifdef ENOMSG + ERRNO_CASE(ENOMSG); +#endif + +#ifdef ENOPROTOOPT + ERRNO_CASE(ENOPROTOOPT); +#endif + +#ifdef ENOSPC + ERRNO_CASE(ENOSPC); +#endif + +#ifdef ENOSR + ERRNO_CASE(ENOSR); +#endif + +#ifdef ENOSTR + ERRNO_CASE(ENOSTR); +#endif + +#ifdef ENOSYS + ERRNO_CASE(ENOSYS); +#endif + +#ifdef ENOTCONN + ERRNO_CASE(ENOTCONN); +#endif + +#ifdef ENOTDIR + ERRNO_CASE(ENOTDIR); +#endif + +#ifdef ENOTEMPTY + ERRNO_CASE(ENOTEMPTY); +#endif + +#ifdef ENOTSOCK + ERRNO_CASE(ENOTSOCK); +#endif + +#ifdef ENOTSUP + ERRNO_CASE(ENOTSUP); +#else +# ifdef EOPNOTSUPP + ERRNO_CASE(EOPNOTSUPP); +# endif +#endif + +#ifdef ENOTTY + ERRNO_CASE(ENOTTY); +#endif + +#ifdef ENXIO + ERRNO_CASE(ENXIO); +#endif + + +#ifdef EOVERFLOW + ERRNO_CASE(EOVERFLOW); +#endif + +#ifdef EPERM + ERRNO_CASE(EPERM); +#endif + +#ifdef EPIPE + ERRNO_CASE(EPIPE); +#endif + +#ifdef EPROTO + ERRNO_CASE(EPROTO); +#endif + +#ifdef EPROTONOSUPPORT + ERRNO_CASE(EPROTONOSUPPORT); +#endif + +#ifdef EPROTOTYPE + ERRNO_CASE(EPROTOTYPE); +#endif + +#ifdef ERANGE + ERRNO_CASE(ERANGE); +#endif + +#ifdef EROFS + ERRNO_CASE(EROFS); +#endif + +#ifdef ESPIPE + ERRNO_CASE(ESPIPE); +#endif + +#ifdef ESRCH + ERRNO_CASE(ESRCH); +#endif + +#ifdef ESTALE + ERRNO_CASE(ESTALE); +#endif + +#ifdef ETIME + ERRNO_CASE(ETIME); +#endif + +#ifdef ETIMEDOUT + ERRNO_CASE(ETIMEDOUT); +#endif + +#ifdef ETXTBSY + ERRNO_CASE(ETXTBSY); +#endif + +#ifdef EXDEV + ERRNO_CASE(EXDEV); +#endif + + default: return ""; + } +} + + +Local ErrnoException(int errorno, + const char *syscall, + const char *msg) { + Local estring = String::NewSymbol(errno_string(errorno)); + if (!msg[0]) msg = strerror(errorno); + Local message = String::NewSymbol(msg); + + Local cons1 = String::Concat(estring, String::NewSymbol(", ")); + Local cons2 = String::Concat(cons1, message); + + Local e = Exception::Error(cons2); + + Local obj = e->ToObject(); + + if (errno_symbol.IsEmpty()) { + syscall_symbol = NODE_PSYMBOL("syscall"); + errno_symbol = NODE_PSYMBOL("errno"); + } + + obj->Set(errno_symbol, Integer::New(errorno)); + if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall)); + return e; +} + + enum encoding ParseEncoding(Handle encoding_v, enum encoding _default) { HandleScope scope; diff --git a/src/node.h b/src/node.h index 44cf0dbd53c..7f2adb8e5fb 100644 --- a/src/node.h +++ b/src/node.h @@ -77,5 +77,9 @@ static inline void cb_destroy(v8::Persistent * cb) { delete cb; } +v8::Local ErrnoException(int errorno, + const char *syscall = NULL, + const char *msg = ""); + } // namespace node #endif // SRC_NODE_H_ diff --git a/src/node_cares.cc b/src/node_cares.cc index 076540d8f73..cfc19b01e23 100644 --- a/src/node_cares.cc +++ b/src/node_cares.cc @@ -77,7 +77,6 @@ struct QueryArg { Persistent Channel::constructor_template; -static Persistent errno_symbol; static Persistent priority_symbol; static Persistent weight_symbol; static Persistent port_symbol; @@ -98,7 +97,6 @@ void Cares::Initialize(Handle target) { target->Set(String::NewSymbol("SOCKET_BAD"), Integer::New(ARES_SOCKET_BAD)); - errno_symbol = NODE_PSYMBOL("errno"); priority_symbol = NODE_PSYMBOL("priority"); weight_symbol = NODE_PSYMBOL("weight"); port_symbol = NODE_PSYMBOL("port"); @@ -166,9 +164,7 @@ static Local HostEntToNames(struct hostent* hostent) { static void ResolveError(Persistent &cb, int status) { HandleScope scope; - Local e = Exception::Error(String::NewSymbol(ares_strerror(status))); - Local obj = e->ToObject(); - obj->Set(errno_symbol, Integer::New(status)); + Local e = ErrnoException(status, NULL, ares_strerror(status)); TryCatch try_catch; diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 8548c179fac..84c3d604edf 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -352,23 +352,6 @@ static int verify_callback(int ok, X509_STORE_CTX *ctx) { return(ok); } -static inline Local ErrnoException(int errorno, - const char *syscall, - const char *msg = "") { - Local estring = String::NewSymbol(errno_string(errorno)); - if (!msg[0]) msg = strerror(errorno); - Local message = String::NewSymbol(msg); - - Local cons1 = String::Concat(estring, String::NewSymbol(", ")); - Local cons2 = String::Concat(cons1, message); - - Local e = Exception::Error(cons2); - - Local obj = e->ToObject(); - obj->Set(errno_symbol, Integer::New(errorno)); - obj->Set(syscall_symbol, String::NewSymbol(syscall)); - return e; -} void SecureContext::Initialize(Handle target) { HandleScope scope; diff --git a/src/node_events.cc b/src/node_events.cc index 4efe5c10e71..c43225a528a 100644 --- a/src/node_events.cc +++ b/src/node_events.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/src/node_file.cc b/src/node_file.cc index 5ca5416506c..5d44808eb25 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1,4 +1,5 @@ // Copyright 2009 Ryan Dahl +#include #include #include @@ -28,13 +29,6 @@ using namespace v8; static Persistent encoding_symbol; static Persistent errno_symbol; -static inline Local errno_exception(int errorno) { - Local e = Exception::Error(String::NewSymbol(strerror(errorno))); - Local obj = e->ToObject(); - obj->Set(errno_symbol, Integer::New(errorno)); - return e; -} - static int After(eio_req *req) { HandleScope scope; @@ -47,7 +41,7 @@ static int After(eio_req *req) { if (req->errorno != 0) { argc = 1; - argv[0] = errno_exception(req->errorno); + argv[0] = ErrnoException(req->errorno); } else { // Note: the error is always given the first argument of the callback. // If there is no error then then the first argument is null. @@ -171,7 +165,7 @@ static Handle Close(const Arguments& args) { ASYNC_CALL(close, args[1], fd) } else { int ret = close(fd); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -190,7 +184,7 @@ static Handle Stat(const Arguments& args) { } else { struct stat s; int ret = stat(*path, &s); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return scope.Close(BuildStatsObject(&s)); } } @@ -209,7 +203,7 @@ static Handle LStat(const Arguments& args) { } else { struct stat s; int ret = lstat(*path, &s); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return scope.Close(BuildStatsObject(&s)); } } @@ -228,7 +222,7 @@ static Handle Symlink(const Arguments& args) { ASYNC_CALL(symlink, args[2], *dest, *path) } else { int ret = symlink(*dest, *path); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -247,7 +241,7 @@ static Handle Link(const Arguments& args) { ASYNC_CALL(link, args[2], *orig_path, *new_path) } else { int ret = link(*orig_path, *new_path); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -266,7 +260,7 @@ static Handle ReadLink(const Arguments& args) { } else { char buf[PATH_MAX]; ssize_t bz = readlink(*path, buf, PATH_MAX); - if (bz == -1) return ThrowException(errno_exception(errno)); + if (bz == -1) return ThrowException(ErrnoException(errno)); return scope.Close(String::New(buf, bz)); } } @@ -285,7 +279,7 @@ static Handle Rename(const Arguments& args) { ASYNC_CALL(rename, args[2], *old_path, *new_path) } else { int ret = rename(*old_path, *new_path); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -304,7 +298,7 @@ static Handle Truncate(const Arguments& args) { ASYNC_CALL(ftruncate, args[2], fd, len) } else { int ret = ftruncate(fd, len); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -322,7 +316,7 @@ static Handle Unlink(const Arguments& args) { ASYNC_CALL(unlink, args[1], *path) } else { int ret = unlink(*path); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -340,7 +334,7 @@ static Handle RMDir(const Arguments& args) { ASYNC_CALL(rmdir, args[1], *path) } else { int ret = rmdir(*path); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -359,7 +353,7 @@ static Handle MKDir(const Arguments& args) { ASYNC_CALL(mkdir, args[2], *path, mode) } else { int ret = mkdir(*path, mode); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } @@ -384,7 +378,7 @@ static Handle SendFile(const Arguments& args) { } else { ssize_t sent = eio_sendfile_sync (out_fd, in_fd, in_offset, length); // XXX is this the right errno to use? - if (sent < 0) return ThrowException(errno_exception(errno)); + if (sent < 0) return ThrowException(ErrnoException(errno)); return Integer::New(sent); } } @@ -402,7 +396,7 @@ static Handle ReadDir(const Arguments& args) { ASYNC_CALL(readdir, args[1], *path, 0 /*flags*/) } else { DIR *dir = opendir(*path); - if (!dir) return ThrowException(errno_exception(errno)); + if (!dir) return ThrowException(ErrnoException(errno)); struct dirent *ent; @@ -443,7 +437,7 @@ static Handle Open(const Arguments& args) { ASYNC_CALL(open, args[3], *path, flags, mode) } else { int fd = open(*path, flags, mode); - if (fd < 0) return ThrowException(errno_exception(errno)); + if (fd < 0) return ThrowException(ErrnoException(errno)); return scope.Close(Integer::New(fd)); } } @@ -561,7 +555,7 @@ static Handle Write(const Arguments& args) { } else { written = pwrite(fd, buf, len, pos); } - if (written < 0) return ThrowException(errno_exception(errno)); + if (written < 0) return ThrowException(ErrnoException(errno)); return scope.Close(Integer::New(written)); } } @@ -600,7 +594,7 @@ static Handle Read(const Arguments& args) { } else { ret = pread(fd, buf, MIN(len, READ_BUF_LEN), offset); } - if (ret < 0) return ThrowException(errno_exception(errno)); + if (ret < 0) return ThrowException(ErrnoException(errno)); Local a = Array::New(2); a->Set(Integer::New(0), Encode(buf, ret, encoding)); a->Set(Integer::New(1), Integer::New(ret)); @@ -624,7 +618,7 @@ static Handle Chmod(const Arguments& args){ ASYNC_CALL(chmod, args[2], *path, mode); } else { int ret = chmod(*path, mode); - if (ret != 0) return ThrowException(errno_exception(errno)); + if (ret != 0) return ThrowException(ErrnoException(errno)); return Undefined(); } } diff --git a/src/node_net2.cc b/src/node_net2.cc index 52e179e60b9..b554c69ac33 100644 --- a/src/node_net2.cc +++ b/src/node_net2.cc @@ -55,346 +55,6 @@ static Persistent recv_msg_template; } -static inline const char *errno_string(int errorno) { -#define ERRNO_CASE(e) case e: return #e; - switch (errorno) { - -#ifdef EACCES - ERRNO_CASE(EACCES); -#endif - -#ifdef EADDRINUSE - ERRNO_CASE(EADDRINUSE); -#endif - -#ifdef EADDRNOTAVAIL - ERRNO_CASE(EADDRNOTAVAIL); -#endif - -#ifdef EAFNOSUPPORT - ERRNO_CASE(EAFNOSUPPORT); -#endif - -#ifdef EAGAIN - ERRNO_CASE(EAGAIN); -#else -# ifdef EWOULDBLOCK - ERRNO_CASE(EWOULDBLOCK); -# endif -#endif - -#ifdef EALREADY - ERRNO_CASE(EALREADY); -#endif - -#ifdef EBADF - ERRNO_CASE(EBADF); -#endif - -#ifdef EBADMSG - ERRNO_CASE(EBADMSG); -#endif - -#ifdef EBUSY - ERRNO_CASE(EBUSY); -#endif - -#ifdef ECANCELED - ERRNO_CASE(ECANCELED); -#endif - -#ifdef ECHILD - ERRNO_CASE(ECHILD); -#endif - -#ifdef ECONNABORTED - ERRNO_CASE(ECONNABORTED); -#endif - -#ifdef ECONNREFUSED - ERRNO_CASE(ECONNREFUSED); -#endif - -#ifdef ECONNRESET - ERRNO_CASE(ECONNRESET); -#endif - -#ifdef EDEADLK - ERRNO_CASE(EDEADLK); -#endif - -#ifdef EDESTADDRREQ - ERRNO_CASE(EDESTADDRREQ); -#endif - -#ifdef EDOM - ERRNO_CASE(EDOM); -#endif - -#ifdef EDQUOT - ERRNO_CASE(EDQUOT); -#endif - -#ifdef EEXIST - ERRNO_CASE(EEXIST); -#endif - -#ifdef EFAULT - ERRNO_CASE(EFAULT); -#endif - -#ifdef EFBIG - ERRNO_CASE(EFBIG); -#endif - -#ifdef EHOSTUNREACH - ERRNO_CASE(EHOSTUNREACH); -#endif - -#ifdef EIDRM - ERRNO_CASE(EIDRM); -#endif - -#ifdef EILSEQ - ERRNO_CASE(EILSEQ); -#endif - -#ifdef EINPROGRESS - ERRNO_CASE(EINPROGRESS); -#endif - -#ifdef EINTR - ERRNO_CASE(EINTR); -#endif - -#ifdef EINVAL - ERRNO_CASE(EINVAL); -#endif - -#ifdef EIO - ERRNO_CASE(EIO); -#endif - -#ifdef EISCONN - ERRNO_CASE(EISCONN); -#endif - -#ifdef EISDIR - ERRNO_CASE(EISDIR); -#endif - -#ifdef ELOOP - ERRNO_CASE(ELOOP); -#endif - -#ifdef EMFILE - ERRNO_CASE(EMFILE); -#endif - -#ifdef EMLINK - ERRNO_CASE(EMLINK); -#endif - -#ifdef EMSGSIZE - ERRNO_CASE(EMSGSIZE); -#endif - -#ifdef EMULTIHOP - ERRNO_CASE(EMULTIHOP); -#endif - -#ifdef ENAMETOOLONG - ERRNO_CASE(ENAMETOOLONG); -#endif - -#ifdef ENETDOWN - ERRNO_CASE(ENETDOWN); -#endif - -#ifdef ENETRESET - ERRNO_CASE(ENETRESET); -#endif - -#ifdef ENETUNREACH - ERRNO_CASE(ENETUNREACH); -#endif - -#ifdef ENFILE - ERRNO_CASE(ENFILE); -#endif - -#ifdef ENOBUFS - ERRNO_CASE(ENOBUFS); -#endif - -#ifdef ENODATA - ERRNO_CASE(ENODATA); -#endif - -#ifdef ENODEV - ERRNO_CASE(ENODEV); -#endif - -#ifdef ENOENT - ERRNO_CASE(ENOENT); -#endif - -#ifdef ENOEXEC - ERRNO_CASE(ENOEXEC); -#endif - -#ifdef ENOLCK - ERRNO_CASE(ENOLCK); -#endif - -#ifdef ENOLINK - ERRNO_CASE(ENOLINK); -#endif - -#ifdef ENOMEM - ERRNO_CASE(ENOMEM); -#endif - -#ifdef ENOMSG - ERRNO_CASE(ENOMSG); -#endif - -#ifdef ENOPROTOOPT - ERRNO_CASE(ENOPROTOOPT); -#endif - -#ifdef ENOSPC - ERRNO_CASE(ENOSPC); -#endif - -#ifdef ENOSR - ERRNO_CASE(ENOSR); -#endif - -#ifdef ENOSTR - ERRNO_CASE(ENOSTR); -#endif - -#ifdef ENOSYS - ERRNO_CASE(ENOSYS); -#endif - -#ifdef ENOTCONN - ERRNO_CASE(ENOTCONN); -#endif - -#ifdef ENOTDIR - ERRNO_CASE(ENOTDIR); -#endif - -#ifdef ENOTEMPTY - ERRNO_CASE(ENOTEMPTY); -#endif - -#ifdef ENOTSOCK - ERRNO_CASE(ENOTSOCK); -#endif - -#ifdef ENOTSUP - ERRNO_CASE(ENOTSUP); -#else -# ifdef EOPNOTSUPP - ERRNO_CASE(EOPNOTSUPP); -# endif -#endif - -#ifdef ENOTTY - ERRNO_CASE(ENOTTY); -#endif - -#ifdef ENXIO - ERRNO_CASE(ENXIO); -#endif - - -#ifdef EOVERFLOW - ERRNO_CASE(EOVERFLOW); -#endif - -#ifdef EPERM - ERRNO_CASE(EPERM); -#endif - -#ifdef EPIPE - ERRNO_CASE(EPIPE); -#endif - -#ifdef EPROTO - ERRNO_CASE(EPROTO); -#endif - -#ifdef EPROTONOSUPPORT - ERRNO_CASE(EPROTONOSUPPORT); -#endif - -#ifdef EPROTOTYPE - ERRNO_CASE(EPROTOTYPE); -#endif - -#ifdef ERANGE - ERRNO_CASE(ERANGE); -#endif - -#ifdef EROFS - ERRNO_CASE(EROFS); -#endif - -#ifdef ESPIPE - ERRNO_CASE(ESPIPE); -#endif - -#ifdef ESRCH - ERRNO_CASE(ESRCH); -#endif - -#ifdef ESTALE - ERRNO_CASE(ESTALE); -#endif - -#ifdef ETIME - ERRNO_CASE(ETIME); -#endif - -#ifdef ETIMEDOUT - ERRNO_CASE(ETIMEDOUT); -#endif - -#ifdef ETXTBSY - ERRNO_CASE(ETXTBSY); -#endif - -#ifdef EXDEV - ERRNO_CASE(EXDEV); -#endif - - default: return ""; - } -} - - -static inline Local ErrnoException(int errorno, - const char *syscall, - const char *msg = "") { - Local estring = String::NewSymbol(errno_string(errorno)); - if (!msg[0]) msg = strerror(errorno); - Local message = String::NewSymbol(msg); - - Local cons1 = String::Concat(estring, String::NewSymbol(", ")); - Local cons2 = String::Concat(cons1, message); - - Local e = Exception::Error(cons2); - - Local obj = e->ToObject(); - obj->Set(errno_symbol, Integer::New(errorno)); - obj->Set(syscall_symbol, String::NewSymbol(syscall)); - return e; -} - static inline bool SetCloseOnExec(int fd) { return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); diff --git a/src/node_stdio.cc b/src/node_stdio.cc index 7af086ddbbf..b5caf0aa3e6 100644 --- a/src/node_stdio.cc +++ b/src/node_stdio.cc @@ -21,14 +21,6 @@ static int stdout_flags = -1; static int stdin_flags = -1; -static Local errno_exception(int errorno) { - Local e = Exception::Error(String::NewSymbol(strerror(errorno))); - Local obj = e->ToObject(); - obj->Set(String::NewSymbol("errno"), Integer::New(errorno)); - return e; -} - - /* STDERR IS ALWAY SYNC ALWAYS UTF8 */ static Handle WriteError (const Arguments& args) @@ -49,7 +41,7 @@ WriteError (const Arguments& args) usleep(100); continue; } - return ThrowException(errno_exception(errno)); + return ThrowException(ErrnoException(errno, "write")); } written += (size_t)r; }