diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js index 744bf2dcab6ec4..c6b47c291e5b24 100644 --- a/lib/internal/buffer.js +++ b/lib/internal/buffer.js @@ -1,5 +1,7 @@ 'use strict'; +const errors = require('internal/errors'); + if (!process.binding('config').hasIntl) { return; } @@ -24,7 +26,7 @@ exports.transcode = function transcode(source, fromEncoding, toEncoding) { return result; const code = icu.icuErrName(result); - const err = new Error(`Unable to transcode Buffer [${code}]`); + const err = new errors.Error('ERR_UNABLE_TRSC_BUFF',code); err.code = code; err.errno = result; throw err; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index f2376f70371c60..7f65062f53120e 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -86,3 +86,4 @@ module.exports = exports = { // Note: Please try to keep these in alphabetical order E('ERR_ASSERTION', (msg) => msg); // Add new errors from here... +E('ERR_UNABLE_TRSC_BUFF', `Unable to transcode Buffer [%s]`); diff --git a/lib/internal/net.js b/lib/internal/net.js index d19bc4c219a796..94ca49418e1888 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -1,5 +1,7 @@ 'use strict'; +const errors = require('internal/errors'); + module.exports = { isLegalPort, assertPort }; // Check that the port number is not NaN when coerced to a number, @@ -14,5 +16,5 @@ function isLegalPort(port) { function assertPort(port) { if (typeof port !== 'undefined' && !isLegalPort(port)) - throw new RangeError('"port" argument must be >= 0 and < 65536'); + throw errors.RangeError('ERR_PORT_ARGUMENT',port); }