mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
Reimplement uv.errname() as internal/util.getSystemErrorName() to avoid the memory leaks caused by unknown error codes and avoid calling into C++ for the error names. Also expose it as a public API for external use. Backport-PR-URL: https://github.com/nodejs/node/pull/19191 PR-URL: https://github.com/nodejs/node/pull/18186 Refs: http://docs.libuv.org/en/v1.x/errors.html#c.uv_err_name Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
36 lines
882 B
JavaScript
36 lines
882 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const {
|
|
getSystemErrorName,
|
|
_errnoException
|
|
} = require('util');
|
|
|
|
const uv = process.binding('uv');
|
|
const keys = Object.keys(uv);
|
|
|
|
keys.forEach((key) => {
|
|
if (!key.startsWith('UV_'))
|
|
return;
|
|
|
|
assert.doesNotThrow(() => {
|
|
const err = _errnoException(uv[key], 'test');
|
|
const name = uv.errname(uv[key]);
|
|
assert.strictEqual(getSystemErrorName(uv[key]), name);
|
|
assert.strictEqual(err.code, name);
|
|
assert.strictEqual(err.code, err.errno);
|
|
assert.strictEqual(err.message, `test ${name}`);
|
|
});
|
|
});
|
|
|
|
[0, 1, 'test', {}, [], Infinity, -Infinity, NaN].forEach((key) => {
|
|
common.expectsError(
|
|
() => _errnoException(key),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "err" argument must be of type negative number'
|
|
});
|
|
});
|