Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Windows: ErrnoException shouldn't mix up crt and win32 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Nov 4, 2011
1 parent 189dd8f commit 6ee73a2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 233 deletions.
269 changes: 37 additions & 232 deletions src/node.cc
Expand Up @@ -605,234 +605,6 @@ static inline const char *errno_string(int errorno) {
ERRNO_CASE(EXDEV);
#endif

#ifdef WSAEINTR
ERRNO_CASE(WSAEINTR);
#endif

#ifdef WSAEBADF
ERRNO_CASE(WSAEBADF);
#endif

#ifdef WSAEACCES
ERRNO_CASE(WSAEACCES);
#endif

#ifdef WSAEFAULT
ERRNO_CASE(WSAEFAULT);
#endif

#ifdef WSAEINVAL
ERRNO_CASE(WSAEINVAL);
#endif

#ifdef WSAEMFILE
ERRNO_CASE(WSAEMFILE);
#endif

#ifdef WSAEWOULDBLOCK
ERRNO_CASE(WSAEWOULDBLOCK);
#endif

#ifdef WSAEINPROGRESS
ERRNO_CASE(WSAEINPROGRESS);
#endif

#ifdef WSAEALREADY
ERRNO_CASE(WSAEALREADY);
#endif

#ifdef WSAENOTSOCK
ERRNO_CASE(WSAENOTSOCK);
#endif

#ifdef WSAEDESTADDRREQ
ERRNO_CASE(WSAEDESTADDRREQ);
#endif

#ifdef WSAEMSGSIZE
ERRNO_CASE(WSAEMSGSIZE);
#endif

#ifdef WSAEPROTOTYPE
ERRNO_CASE(WSAEPROTOTYPE);
#endif

#ifdef WSAENOPROTOOPT
ERRNO_CASE(WSAENOPROTOOPT);
#endif

#ifdef WSAEPROTONOSUPPORT
ERRNO_CASE(WSAEPROTONOSUPPORT);
#endif

#ifdef WSAESOCKTNOSUPPORT
ERRNO_CASE(WSAESOCKTNOSUPPORT);
#endif

#ifdef WSAEOPNOTSUPP
ERRNO_CASE(WSAEOPNOTSUPP);
#endif

#ifdef WSAEPFNOSUPPORT
ERRNO_CASE(WSAEPFNOSUPPORT);
#endif

#ifdef WSAEAFNOSUPPORT
ERRNO_CASE(WSAEAFNOSUPPORT);
#endif

#ifdef WSAEADDRINUSE
ERRNO_CASE(WSAEADDRINUSE);
#endif

#ifdef WSAEADDRNOTAVAIL
ERRNO_CASE(WSAEADDRNOTAVAIL);
#endif

#ifdef WSAENETDOWN
ERRNO_CASE(WSAENETDOWN);
#endif

#ifdef WSAENETUNREACH
ERRNO_CASE(WSAENETUNREACH);
#endif

#ifdef WSAENETRESET
ERRNO_CASE(WSAENETRESET);
#endif

#ifdef WSAECONNABORTED
ERRNO_CASE(WSAECONNABORTED);
#endif

#ifdef WSAECONNRESET
ERRNO_CASE(WSAECONNRESET);
#endif

#ifdef WSAENOBUFS
ERRNO_CASE(WSAENOBUFS);
#endif

#ifdef WSAEISCONN
ERRNO_CASE(WSAEISCONN);
#endif

#ifdef WSAENOTCONN
ERRNO_CASE(WSAENOTCONN);
#endif

#ifdef WSAESHUTDOWN
ERRNO_CASE(WSAESHUTDOWN);
#endif

#ifdef WSAETOOMANYREFS
ERRNO_CASE(WSAETOOMANYREFS);
#endif

#ifdef WSAETIMEDOUT
ERRNO_CASE(WSAETIMEDOUT);
#endif

#ifdef WSAECONNREFUSED
ERRNO_CASE(WSAECONNREFUSED);
#endif

#ifdef WSAELOOP
ERRNO_CASE(WSAELOOP);
#endif

#ifdef WSAENAMETOOLONG
ERRNO_CASE(WSAENAMETOOLONG);
#endif

#ifdef WSAEHOSTDOWN
ERRNO_CASE(WSAEHOSTDOWN);
#endif

#ifdef WSAEHOSTUNREACH
ERRNO_CASE(WSAEHOSTUNREACH);
#endif

#ifdef WSAENOTEMPTY
ERRNO_CASE(WSAENOTEMPTY);
#endif

#ifdef WSAEPROCLIM
ERRNO_CASE(WSAEPROCLIM);
#endif

#ifdef WSAEUSERS
ERRNO_CASE(WSAEUSERS);
#endif

#ifdef WSAEDQUOT
ERRNO_CASE(WSAEDQUOT);
#endif

#ifdef WSAESTALE
ERRNO_CASE(WSAESTALE);
#endif

#ifdef WSAEREMOTE
ERRNO_CASE(WSAEREMOTE);
#endif

#ifdef WSASYSNOTREADY
ERRNO_CASE(WSASYSNOTREADY);
#endif

#ifdef WSAVERNOTSUPPORTED
ERRNO_CASE(WSAVERNOTSUPPORTED);
#endif

#ifdef WSANOTINITIALISED
ERRNO_CASE(WSANOTINITIALISED);
#endif

#ifdef WSAEDISCON
ERRNO_CASE(WSAEDISCON);
#endif

#ifdef WSAENOMORE
ERRNO_CASE(WSAENOMORE);
#endif

#ifdef WSAECANCELLED
ERRNO_CASE(WSAECANCELLED);
#endif

#ifdef WSAEINVALIDPROCTABLE
ERRNO_CASE(WSAEINVALIDPROCTABLE);
#endif

#ifdef WSAEINVALIDPROVIDER
ERRNO_CASE(WSAEINVALIDPROVIDER);
#endif

#ifdef WSAEPROVIDERFAILEDINIT
ERRNO_CASE(WSAEPROVIDERFAILEDINIT);
#endif

#ifdef WSASYSCALLFAILURE
ERRNO_CASE(WSASYSCALLFAILURE);
#endif

#ifdef WSASERVICE_NOT_FOUND
ERRNO_CASE(WSASERVICE_NOT_FOUND);
#endif

#ifdef WSATYPE_NOT_FOUND
ERRNO_CASE(WSATYPE_NOT_FOUND);
#endif

#ifdef WSA_E_NO_MORE
ERRNO_CASE(WSA_E_NO_MORE);
#endif

#ifdef WSA_E_CANCELLED
ERRNO_CASE(WSA_E_CANCELLED);
#endif

default: return "";
}
}
Expand Down Expand Up @@ -994,11 +766,7 @@ Local<Value> ErrnoException(int errorno,
Local<Value> e;
Local<String> estring = String::NewSymbol(errno_string(errorno));
if (!msg[0]) {
#ifdef __POSIX__
msg = strerror(errorno);
#else // __MINGW32__
msg = winapi_strerror(errorno);
#endif
}
Local<String> message = String::NewSymbol(msg);

Expand Down Expand Up @@ -1031,6 +799,43 @@ Local<Value> ErrnoException(int errorno,
}


#ifdef _WIN32
Local<Value> WinapiErrnoException(int errorno,
const char *syscall,
const char *msg,
const char *path) {

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Nov 4, 2011

Member

Style issue: const char*, not const char *

Local<Value> e;
if (!msg[0]) {

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Nov 4, 2011

Member
if (!msg || !msg[0]) {

?

This comment has been minimized.

Copy link
@piscisaureus

piscisaureus Nov 4, 2011

Author

msg defaults to ""

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Nov 4, 2011

Member

That's what annoys me about ErrnoException() - if you want to provide a path but not an error message, you need to pass in an empty string. It's counter-intuitive, easy to forget.

msg = winapi_strerror(errorno);
}
Local<String> message = String::NewSymbol(msg);

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 (path) {
Local<String> cons1 = String::Concat(message, String::NewSymbol(" '"));
Local<String> cons2 = String::Concat(cons1, String::New(path));
Local<String> cons3 = String::Concat(cons2, String::NewSymbol("'"));
e = Exception::Error(cons3);
} else {
e = Exception::Error(message);
}

Local<Object> obj = e->ToObject();

obj->Set(errno_symbol, Integer::New(errorno));
if (path) obj->Set(errpath_symbol, String::New(path));
if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
return e;
}
#endif


Handle<Value> FromConstructorTemplate(Persistent<FunctionTemplate>& t,
const Arguments& args) {
HandleScope scope;
Expand Down
7 changes: 6 additions & 1 deletion src/node.h
Expand Up @@ -147,7 +147,7 @@ ssize_t DecodeWrite(char *buf,
# define NODE_STAT stat
# define NODE_FSTAT fstat
# define NODE_STAT_STRUCT struct stat
#else // __MINGW32__
#else // _WIN32
# define NODE_STAT _stati64
# define NODE_FSTAT _fstati64
# define NODE_STAT_STRUCT struct _stati64
Expand Down Expand Up @@ -191,6 +191,11 @@ NODE_EXTERN v8::Local<v8::Value> ErrnoException(int errorno,
const char *syscall = NULL,
const char *msg = "",
const char *path = NULL);
#ifdef _WIN32
NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(int errorno,
const char *syscall = NULL, const char *msg = "",
const char *path = NULL);
#endif

const char *signo_string(int errorno);

Expand Down

0 comments on commit 6ee73a2

Please sign in to comment.