From aa95e5708f240810cd434911cf029f5ee70047d8 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 4 Feb 2011 14:35:14 -0800 Subject: [PATCH] Expose errno with a string. --- doc/api/net.markdown | 2 +- src/node.cc | 3 +++ test/simple/test-net-connect-handle-econnrefused.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/api/net.markdown b/doc/api/net.markdown index e505633..bcb2c96 100644 --- a/doc/api/net.markdown +++ b/doc/api/net.markdown @@ -70,7 +70,7 @@ another server is already running on the requested port. One way of handling thi would be to wait a second and the try again. This can be done with server.on('error', function (e) { - if (e.errno == require('constants').EADDRINUSE) { + if (e.code == 'EADDRINUSE') { console.log('Address in use, retrying...'); setTimeout(function () { server.close(); diff --git a/src/node.cc b/src/node.cc index 582b0d2..2e1e6b3 100644 --- a/src/node.cc +++ b/src/node.cc @@ -71,6 +71,7 @@ static Persistent process; static Persistent errno_symbol; static Persistent syscall_symbol; static Persistent errpath_symbol; +static Persistent code_symbol; static Persistent rss_symbol; static Persistent vsize_symbol; @@ -1021,6 +1022,7 @@ Local ErrnoException(int errorno, syscall_symbol = NODE_PSYMBOL("syscall"); errno_symbol = NODE_PSYMBOL("errno"); errpath_symbol = NODE_PSYMBOL("path"); + code_symbol = NODE_PSYMBOL("code"); } if (path) { @@ -1035,6 +1037,7 @@ Local ErrnoException(int errorno, Local obj = e->ToObject(); obj->Set(errno_symbol, Integer::New(errorno)); + obj->Set(code_symbol, estring); if (path) obj->Set(errpath_symbol, String::New(path)); if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall)); return e; diff --git a/test/simple/test-net-connect-handle-econnrefused.js b/test/simple/test-net-connect-handle-econnrefused.js index 39f729b..a96473d 100644 --- a/test/simple/test-net-connect-handle-econnrefused.js +++ b/test/simple/test-net-connect-handle-econnrefused.js @@ -16,6 +16,7 @@ c.on('error', function(e) { console.error('couldn\'t connect.'); gotError = true; assert.equal(require('constants').ECONNREFUSED, e.errno); + assert.equal('ECONNREFUSED', e.code); }); -- 2.7.4