1// Flags: --expose-internals 2'use strict'; 3 4const common = require('../common'); 5const assert = require('assert'); 6const { 7 getSystemErrorName, 8 _errnoException 9} = require('util'); 10 11const { internalBinding } = require('internal/test/binding'); 12const uv = internalBinding('uv'); 13const keys = Object.keys(uv); 14 15keys.forEach((key) => { 16 if (!key.startsWith('UV_')) 17 return; 18 19 const err = _errnoException(uv[key], 'test'); 20 const name = uv.errname(uv[key]); 21 assert.strictEqual(getSystemErrorName(uv[key]), name); 22 assert.strictEqual(err.code, name); 23 assert.strictEqual(err.code, getSystemErrorName(err.errno)); 24 assert.strictEqual(err.message, `test ${name}`); 25}); 26 27function runTest(fn) { 28 ['test', {}, []].forEach((err) => { 29 assert.throws( 30 () => fn(err), 31 { 32 code: 'ERR_INVALID_ARG_TYPE', 33 name: 'TypeError', 34 message: 'The "err" argument must be of type number.' + 35 common.invalidArgTypeHelper(err) 36 }); 37 }); 38 39 [0, 1, Infinity, -Infinity, NaN].forEach((err) => { 40 assert.throws( 41 () => fn(err), 42 { 43 code: 'ERR_OUT_OF_RANGE', 44 name: 'RangeError', 45 message: 'The value of "err" is out of range. ' + 46 'It must be a negative integer. ' + 47 `Received ${err}` 48 }); 49 }); 50} 51 52runTest(_errnoException); 53runTest(getSystemErrorName); 54