summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-04-01 07:38:47 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-04-05 11:07:41 +0200
commit22da2f731d90235289a95bffe1ae3750a62a33bc (patch)
tree9c63afcdc504b66215e7df6fe3474526d5c74714 /lib
parent354849eeb595ac364337e564669de4c77aa4c1af (diff)
downloadandroid-node-v8-22da2f731d90235289a95bffe1ae3750a62a33bc.tar.gz
android-node-v8-22da2f731d90235289a95bffe1ae3750a62a33bc.tar.bz2
android-node-v8-22da2f731d90235289a95bffe1ae3750a62a33bc.zip
errors: make message non-enumerable
A error message should always be non-enumerable. This makes sure that is true for dns errors as well. It also adds another check in `common.expectsError` to make sure no other regressions are introduced going forward. Fixes #19716 PR-URL: https://github.com/nodejs/node/pull/19719 Fixes: https://github.com/nodejs/node/issues/19716 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/errors.js37
1 files changed, 18 insertions, 19 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 17b6f966d4..3e940c8496 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -550,34 +550,33 @@ function exceptionWithHostPort(err, syscall, address, port, additional) {
}
/**
- * @param {number|string} err - A libuv error number or a c-ares error code
+ * @param {number|string} code - A libuv error number or a c-ares error code
* @param {string} syscall
* @param {string} [hostname]
* @returns {Error}
*/
-function dnsException(err, syscall, hostname) {
- // eslint-disable-next-line no-restricted-syntax
- const ex = new Error();
+function dnsException(code, syscall, hostname) {
+ let message;
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
- if (err === UV_EAI_MEMORY ||
- err === UV_EAI_NODATA ||
- err === UV_EAI_NONAME) {
- err = 'ENOTFOUND'; // Fabricated error name.
+ if (code === UV_EAI_MEMORY ||
+ code === UV_EAI_NODATA ||
+ code === UV_EAI_NONAME) {
+ code = 'ENOTFOUND'; // Fabricated error name.
}
- if (typeof err === 'string') { // c-ares error code.
- const errHost = hostname ? ` ${hostname}` : '';
- ex.message = `${syscall} ${err}${errHost}`;
- // TODO(joyeecheung): errno is supposed to be a number, like in uvException
- ex.code = ex.errno = err;
- ex.syscall = syscall;
+ if (typeof code === 'string') { // c-ares error code.
+ message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`;
} else { // libuv error number
- const code = lazyInternalUtil().getSystemErrorName(err);
- ex.message = `${syscall} ${code}`;
- // TODO(joyeecheung): errno is supposed to be err, like in uvException
- ex.code = ex.errno = code;
- ex.syscall = syscall;
+ code = lazyInternalUtil().getSystemErrorName(code);
+ message = `${syscall} ${code}`;
}
+ // eslint-disable-next-line no-restricted-syntax
+ const ex = new Error(message);
+ // TODO(joyeecheung): errno is supposed to be a number / err, like in
+ // uvException.
+ ex.errno = code;
+ ex.code = code;
+ ex.syscall = syscall;
if (hostname) {
ex.hostname = hostname;
}