summaryrefslogtreecommitdiff
path: root/lib/net.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-18 15:41:19 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-21 22:52:08 +0100
commit39f4158bc38ff2925b86563082c8d26ab3d20b17 (patch)
tree9e1a669fd41379bcd9b85bdf0e17fde5033a2c77 /lib/net.js
parentdf0870dddf15ab5396ab9842fdbe4c06a8186cda (diff)
downloadandroid-node-v8-39f4158bc38ff2925b86563082c8d26ab3d20b17.tar.gz
android-node-v8-39f4158bc38ff2925b86563082c8d26ab3d20b17.tar.bz2
android-node-v8-39f4158bc38ff2925b86563082c8d26ab3d20b17.zip
lib: move extra properties into error creation
This encapsulates the Node.js errors more by adding extra properties to an error inside of the function to create the error message instead of adding the properties at the call site. That simplifies the usage of our errors and makes sure the expected properties are always set. PR-URL: https://github.com/nodejs/node/pull/26752 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/net.js')
-rw-r--r--lib/net.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/net.js b/lib/net.js
index ecf7258e8b..a5f012ac33 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -968,19 +968,20 @@ function lookupAndConnect(self, options) {
if (!self.connecting) return;
if (err) {
- // net.createConnection() creates a net.Socket object and
- // immediately calls net.Socket.connect() on it (that's us).
- // There are no event listeners registered yet so defer the
- // error event to the next tick.
+ // net.createConnection() creates a net.Socket object and immediately
+ // calls net.Socket.connect() on it (that's us). There are no event
+ // listeners registered yet so defer the error event to the next tick.
+ // TODO(BridgeAR): The error could either originate from user code or
+ // by the C++ layer. The port is never the cause for the error as it is
+ // not used in the lookup. We should probably just remove this.
err.host = options.host;
err.port = options.port;
err.message = err.message + ' ' + options.host + ':' + options.port;
process.nextTick(connectErrorNT, self, err);
} else if (addressType !== 4 && addressType !== 6) {
- err = new ERR_INVALID_ADDRESS_FAMILY(addressType);
- err.host = options.host;
- err.port = options.port;
- err.message = err.message + ' ' + options.host + ':' + options.port;
+ err = new ERR_INVALID_ADDRESS_FAMILY(addressType,
+ options.host,
+ options.port);
process.nextTick(connectErrorNT, self, err);
} else {
self._unrefTimer();