From: Ryan Dahl Date: Mon, 17 May 2010 20:58:15 +0000 (-0700) Subject: Fix errno display in c-ares exceptions X-Git-Tag: v0.1.96~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1036aa9762c7f08a0f0e9552da7c4fbbb6eec091;p=platform%2Fupstream%2Fnodejs.git Fix errno display in c-ares exceptions --- diff --git a/src/node_cares.cc b/src/node_cares.cc index c09ee84..f9e1a1a 100644 --- a/src/node_cares.cc +++ b/src/node_cares.cc @@ -167,11 +167,54 @@ static Local HostEntToNames(struct hostent* hostent) { return names; } +static inline const char *ares_errno_string(int errorno) { +#define ERRNO_CASE(e) case ARES_##e: return #e; + switch (errorno) { + ERRNO_CASE(SUCCESS) + ERRNO_CASE(ENODATA) + ERRNO_CASE(EFORMERR) + ERRNO_CASE(ESERVFAIL) + ERRNO_CASE(ENOTFOUND) + ERRNO_CASE(ENOTIMP) + ERRNO_CASE(EREFUSED) + ERRNO_CASE(EBADQUERY) + ERRNO_CASE(EBADNAME) + ERRNO_CASE(EBADFAMILY) + ERRNO_CASE(EBADRESP) + ERRNO_CASE(ECONNREFUSED) + ERRNO_CASE(ETIMEOUT) + ERRNO_CASE(EOF) + ERRNO_CASE(EFILE) + ERRNO_CASE(ENOMEM) + ERRNO_CASE(EDESTRUCTION) + ERRNO_CASE(EBADSTR) + ERRNO_CASE(EBADFLAGS) + ERRNO_CASE(ENONAME) + ERRNO_CASE(EBADHINTS) + ERRNO_CASE(ENOTINITIALIZED) + ERRNO_CASE(ELOADIPHLPAPI) + ERRNO_CASE(EADDRGETNETWORKPARAMS) + ERRNO_CASE(ECANCELLED) + default: + assert(0 && "Unhandled c-ares errno"); + return "(UNKNOWN)"; + } +} + static void ResolveError(Persistent &cb, int status) { HandleScope scope; - Local e = ErrnoException(status, NULL, ares_strerror(status)); + Local code = String::NewSymbol(ares_errno_string(status)); + Local message = String::NewSymbol(ares_strerror(status)); + + Local cons1 = String::Concat(code, String::NewSymbol(", ")); + Local cons2 = String::Concat(cons1, message); + + Local e = Exception::Error(cons2); + + Local obj = e->ToObject(); + obj->Set(String::NewSymbol("errno"), Integer::New(status)); TryCatch try_catch;