summaryrefslogtreecommitdiff
path: root/lib/internal/errors.js
diff options
context:
space:
mode:
authorSagi Tsofan <sagitsofan@gmail.com>2018-09-21 00:59:22 +0300
committerAnna Henningsen <anna@addaleax.net>2018-10-11 21:21:36 -0700
commit82ea7058b6c25ee2c1467665c1b53b2b2b9ca139 (patch)
treeb63c4164162715e77a5f1624ef871055609127f0 /lib/internal/errors.js
parent3f08c004c5c95abc8a2faf7e2ea156c72806b54b (diff)
downloadandroid-node-v8-82ea7058b6c25ee2c1467665c1b53b2b2b9ca139.tar.gz
android-node-v8-82ea7058b6c25ee2c1467665c1b53b2b2b9ca139.tar.bz2
android-node-v8-82ea7058b6c25ee2c1467665c1b53b2b2b9ca139.zip
lib: http server, friendly error messages
Improved error message description for the http server binding errors. Currently changed only in `setupListenHandle`, but needs to be change all over. Added new `uvExceptionWithHostPort` function (+export) in `lib/internal/error.js` that extracts the error message defined by libuv, using the error code, and returns an error object with the full error description. example: old error message: `listen EADDRINUSE` new error message: `listen EADDRINUSE: Address already in use` Removed exportable function `_exceptionWithHostPort` from `lib/util.js` - exported by accident Replaced `exceptionWithHostPort` to the new function `uvExceptionWithHostPort` for a more detailed error. Fixes: https://github.com/nodejs/node/issues/22936 PR-URL: https://github.com/nodejs/node/pull/22995 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/errors.js')
-rw-r--r--lib/internal/errors.js46
1 files changed, 44 insertions, 2 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 4094a40f6b..58eba742e0 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -286,6 +286,46 @@ function uvException(ctx) {
}
/**
+ * This creates an error compatible with errors produced in the C++
+ * This function should replace the deprecated
+ * `exceptionWithHostPort()` function.
+ *
+ * @param {number} err - A libuv error number
+ * @param {string} syscall
+ * @param {string} address
+ * @param {number} [port]
+ * @param {string} [additional]
+ * @returns {Error}
+ */
+function uvExceptionWithHostPort(err, syscall, address, port, additional) {
+ const [ code, uvmsg ] = errmap.get(err);
+ const message = `${syscall} ${code}: ${uvmsg}`;
+ let details = '';
+
+ if (port && port > 0) {
+ details = ` ${address}:${port}`;
+ } else if (address) {
+ details = ` ${address}`;
+ }
+ if (additional) {
+ details += ` - Local (${additional})`;
+ }
+
+ // eslint-disable-next-line no-restricted-syntax
+ const ex = new Error(`${message}${details}`);
+ ex.code = code;
+ ex.errno = code;
+ ex.syscall = syscall;
+ ex.address = address;
+ if (port) {
+ ex.port = port;
+ }
+
+ Error.captureStackTrace(ex, uvExceptionWithHostPort);
+ return ex;
+}
+
+/**
* This used to be util._errnoException().
*
* @param {number} err - A libuv error number
@@ -314,8 +354,9 @@ function errnoException(err, syscall, original) {
}
/**
- * This used to be util._exceptionWithHostPort().
- *
+ * Deprecated, new function is `uvExceptionWithHostPort()`
+ * New function added the error description directly
+ * from C++. this method for backwards compatibility
* @param {number} err - A libuv error number
* @param {string} syscall
* @param {string} address
@@ -437,6 +478,7 @@ module.exports = {
errnoException,
exceptionWithHostPort,
uvException,
+ uvExceptionWithHostPort,
isStackOverflowError,
getMessage,
SystemError,