summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-08-23 16:43:17 -0400
committerRich Trott <rtrott@gmail.com>2019-08-27 11:27:33 -0700
commitc246f813f8b1bbc8f0e13ab77452da4dff437635 (patch)
tree7b0a2bca617cdfe86cfb2bce7389e2091addee0d /lib
parent5ba3a2c4b6dfb928a097b36523d59cd5fa70706b (diff)
downloadandroid-node-v8-c246f813f8b1bbc8f0e13ab77452da4dff437635.tar.gz
android-node-v8-c246f813f8b1bbc8f0e13ab77452da4dff437635.tar.bz2
android-node-v8-c246f813f8b1bbc8f0e13ab77452da4dff437635.zip
errors: provide defaults for unmapped uv errors
libuv does not map 100% of errors. When an unmapped error is encountered, the Map returns undefined, which is then unsuccessfully destructured, causing an exception. This commit adds a default value in the event of an unmapped error. PR-URL: https://github.com/nodejs/node/pull/29288 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/errors.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index cf97a76b36..56c7a3bdbe 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -327,6 +327,8 @@ function lazyUv() {
return uvBinding;
}
+const uvUnmappedError = ['UNKNOWN', 'unknown error'];
+
function uvErrmapGet(name) {
uvBinding = lazyUv();
if (!uvBinding.errmap) {
@@ -346,7 +348,7 @@ function uvErrmapGet(name) {
* @returns {Error}
*/
function uvException(ctx) {
- const [ code, uvmsg ] = uvErrmapGet(ctx.errno);
+ const [ code, uvmsg ] = uvErrmapGet(ctx.errno) || uvUnmappedError;
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;
let path;
@@ -404,7 +406,7 @@ function uvException(ctx) {
* @returns {Error}
*/
function uvExceptionWithHostPort(err, syscall, address, port) {
- const [ code, uvmsg ] = uvErrmapGet(err);
+ const [ code, uvmsg ] = uvErrmapGet(err) || uvUnmappedError;
const message = `${syscall} ${code}: ${uvmsg}`;
let details = '';