Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ function lazyUv() {
return uvBinding;
}

const uvUnmappedError = ['UNKNOWN', 'unknown error'];

function uvErrmapGet(name) {
uvBinding = lazyUv();
if (!uvBinding.errmap) {
Expand All @@ -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;
Expand Down Expand Up @@ -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 = '';

Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-uv-unmapped-exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { uvException, uvExceptionWithHostPort } = require('internal/errors');

{
const exception = uvException({ errno: 100, syscall: 'open' });

assert.strictEqual(exception.message, 'UNKNOWN: unknown error, open');
assert.strictEqual(exception.errno, 100);
assert.strictEqual(exception.syscall, 'open');
assert.strictEqual(exception.code, 'UNKNOWN');
}

{
const exception = uvExceptionWithHostPort(100, 'listen', '127.0.0.1', 80);

assert.strictEqual(exception.message,
'listen UNKNOWN: unknown error 127.0.0.1:80');
assert.strictEqual(exception.code, 'UNKNOWN');
assert.strictEqual(exception.errno, 100);
assert.strictEqual(exception.syscall, 'listen');
assert.strictEqual(exception.address, '127.0.0.1');
assert.strictEqual(exception.port, 80);
}