Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4994b7f
http: add options to http.createServer()
Oct 19, 2017
5bfc1d1
http2: add http fallback options to .createServer
hekike Oct 27, 2017
852b996
http2: add req and res options to server creation
Oct 5, 2017
0829b54
doc: fix typo in http2.md
vsemozhetbyt Feb 19, 2018
f7d96ac
http2: pass session to DEBUG_HTTP2SESSION2
danbev May 18, 2018
83cd22e
tools: speed up lint-md-build
refack Nov 10, 2017
bdbef5f
src: remove superfluous check in backtrace_posix.cc
addaleax Nov 11, 2017
141e3e9
trace_events: add file pattern cli option
AndreasMadsen Jan 31, 2018
b2b85e5
src, test: node internals' postmortem metadata
Dec 26, 2017
d27ca6d
test: fix cctest -Wunused-variable warning
bnoordhuis Feb 2, 2018
591812f
src: do not redefine private for GenDebugSymbols
joyeecheung Feb 8, 2018
3a7ad60
src: expose uv.errmap to binding
joyeecheung Dec 25, 2017
4a55524
util: implement util.getSystemErrorName()
joyeecheung Jan 16, 2018
05076ac
errors: lazy load util in internal/errors.js
joyeecheung Jan 24, 2018
de86203
util: skip type checks in internal getSystemErrorName
joyeecheung Feb 3, 2018
64f4b19
errors: move error creation helpers to errors.js
joyeecheung Feb 3, 2018
a974479
errors: make message non-enumerable
BridgeAR Apr 1, 2018
4406f6e
test: set clientOpts.port property
danbev Apr 3, 2018
4f05d1b
test: remove test case 0 from tls-cnnic-whitelist
danbev Apr 13, 2018
6251f2a
crypto: remove BIO_set_shutdown
danbev Dec 7, 2017
4512116
tools: don't lint-md as part of main lint target
refack Dec 7, 2017
a6d6325
tls: use correct class name in deprecation message
addaleax Dec 9, 2017
4cd0ab5
src: make FSEventWrap/StatWatcher::Start more robust
TimothyGu Dec 3, 2017
e0a780b
url: added space to class string of iterator objects
prohaejin Dec 9, 2017
d81a3f4
url: added url fragment lookup table
Kimeiga Dec 8, 2017
b07b9f2
test: add test for postmortem metadata validation
cjihrig Dec 14, 2017
524efb9
lib, src: use process.config instead of regex
maclover7 Dec 21, 2017
3aefc25
test: fix unreliable async-hooks/test-signalwrap
Trott Dec 22, 2017
14f29e3
src: remove duplicate words in comments
tniessen Jan 1, 2018
b046412
http2: remove duplicate words in comments
tniessen Jan 1, 2018
d8c3ecc
perf_hooks: fix scheduling regression
apapirovski Jan 9, 2018
2b941c6
src: update make for new code coverage locations
mhdawson Jan 4, 2018
a337e3a
src: fix code coverage cleanup
mhdawson Jan 10, 2018
0230caf
test: refactor test-repl
addaleax Dec 31, 2017
07e8195
benchmark: add JSStreamWrap benchmark
addaleax Jan 4, 2018
5b8e46d
src: harden JSStream callbacks
addaleax Jan 7, 2018
0082efd
src: rename `On*` -> `Emit*` for stream callbacks
addaleax Dec 15, 2017
396c96e
build: make gyp user defined variables lowercase
danbev Oct 16, 2017
04c166a
build: add node_lib_target_name to cctest deps
danbev Feb 5, 2018
e37643c
src: refactor callback #defines into C++ templates
addaleax Jan 13, 2018
453077f
http: simplify parser lifetime tracking
addaleax Jan 13, 2018
29f49e9
deps: cherry-pick dbfe4a49d8 from upstream V8
Nov 9, 2017
c4c468b
module: Set dynamic import callback
Oct 1, 2017
a0c7df8
module: enable dynamic import flag for esmodules
MylesBorins Jan 25, 2018
1af6ac2
doc: Update tools/icu/README.md
srl295 Nov 10, 2017
de963da
tools: fix icu readme lint error
apapirovski Jan 30, 2018
1a3c296
stream: delete redundant code
Jan 14, 2018
4b2792a
stream: delete redundant code
Jan 15, 2018
2bbf95c
crypto: use non-deprecated v8::Object::Set
danbev Dec 6, 2017
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
Prev Previous commit
Next Next commit
errors: move error creation helpers to errors.js
This commit moves error creation helpers scattered around
under lib/ into lib/internal/errors.js in the hope of being clearer
about the differences of errors that we throw into the user land.

- Move util._errnoException and util._exceptionWithHostPort
  into internal/errors.js and simplify their logic so it's
  clearer what the properties these helpers create.
- Move the errnoException helper in dns.js to internal/errors.js
  into internal/errors.js and rename it to dnsException. Simplify
  it's logic so it no longer calls errnoException and skips
  the unnecessary argument checks.

Backport-PR-URL: #19191
PR-URL: #18546
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and MylesBorins committed May 22, 2018
commit 64f4b19faf9e595d07655d3dfcb09496407d2255
4 changes: 2 additions & 2 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const SEND_BUFFER = false;
// Lazily loaded
var cluster = null;

const errnoException = util._errnoException;
const exceptionWithHostPort = util._exceptionWithHostPort;
const errnoException = errors.errnoException;
const exceptionWithHostPort = errors.exceptionWithHostPort;


function lookup4(lookup, address, callback) {
Expand Down
43 changes: 9 additions & 34 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

'use strict';

const util = require('util');

const cares = process.binding('cares_wrap');
const uv = process.binding('uv');
const { isLegalPort } = require('internal/net');
const { customPromisifyArgs } = require('internal/util');
const errors = require('internal/errors');

const {
GetAddrInfoReqWrap,
Expand All @@ -36,30 +34,6 @@ const {
isIP
} = cares;

function errnoException(err, syscall, hostname) {
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
if (err === uv.UV_EAI_MEMORY ||
err === uv.UV_EAI_NODATA ||
err === uv.UV_EAI_NONAME) {
err = 'ENOTFOUND';
}
var ex = null;
if (typeof err === 'string') { // c-ares error code.
const errHost = hostname ? ` ${hostname}` : '';
ex = new Error(`${syscall} ${err}${errHost}`);
ex.code = err;
ex.errno = err;
ex.syscall = syscall;
} else {
ex = util._errnoException(err, syscall);
}
if (hostname) {
ex.hostname = hostname;
}
return ex;
}

const IANA_DNS_PORT = 53;
const digits = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15
Expand All @@ -86,10 +60,11 @@ function isIPv4(str) {
return (str.length > 3 && str.charCodeAt(3) === 46/*'.'*/);
}

const dnsException = errors.dnsException;

function onlookup(err, addresses) {
if (err) {
return this.callback(errnoException(err, 'getaddrinfo', this.hostname));
return this.callback(dnsException(err, 'getaddrinfo', this.hostname));
}
if (this.family) {
this.callback(null, addresses[0], this.family);
Expand All @@ -101,7 +76,7 @@ function onlookup(err, addresses) {

function onlookupall(err, addresses) {
if (err) {
return this.callback(errnoException(err, 'getaddrinfo', this.hostname));
return this.callback(dnsException(err, 'getaddrinfo', this.hostname));
}

var family = this.family;
Expand Down Expand Up @@ -181,7 +156,7 @@ function lookup(hostname, options, callback) {

var err = cares.getaddrinfo(req, hostname, family, hints, verbatim);
if (err) {
process.nextTick(callback, errnoException(err, 'getaddrinfo', hostname));
process.nextTick(callback, dnsException(err, 'getaddrinfo', hostname));
return {};
}
return req;
Expand All @@ -193,7 +168,7 @@ Object.defineProperty(lookup, customPromisifyArgs,

function onlookupservice(err, host, service) {
if (err)
return this.callback(errnoException(err, 'getnameinfo', this.host));
return this.callback(dnsException(err, 'getnameinfo', this.host));

this.callback(null, host, service);
}
Expand Down Expand Up @@ -222,7 +197,7 @@ function lookupService(host, port, callback) {
req.oncomplete = onlookupservice;

var err = cares.getnameinfo(req, host, port);
if (err) throw errnoException(err, 'getnameinfo', host);
if (err) throw dnsException(err, 'getnameinfo', host);
return req;
}

Expand All @@ -235,7 +210,7 @@ function onresolve(err, result, ttls) {
result = result.map((address, index) => ({ address, ttl: ttls[index] }));

if (err)
this.callback(errnoException(err, this.bindingName, this.hostname));
this.callback(dnsException(err, this.bindingName, this.hostname));
else
this.callback(null, result);
}
Expand Down Expand Up @@ -272,7 +247,7 @@ function resolver(bindingName) {
req.oncomplete = onresolve;
req.ttl = !!(options && options.ttl);
var err = this._handle[bindingName](req, name);
if (err) throw errnoException(err, bindingName);
if (err) throw dnsException(err, bindingName);
return req;
}
Object.defineProperty(query, 'name', { value: bindingName });
Expand Down
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const { kMaxLength } = require('buffer');
const isWindows = process.platform === 'win32';

const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;
const errnoException = errors.errnoException;

function getOptions(options, defaultOptions) {
if (options === null || options === undefined ||
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SocketList = require('internal/socket_list');
const { convertToValidSignal } = require('internal/util');
const { isUint8Array } = require('internal/util/types');

const errnoException = util._errnoException;
const errnoException = errors.errnoException;
const { SocketListSend, SocketListReceive } = SocketList;

const MAX_HANDLE_RETRANSMISSIONS = 3;
Expand Down
116 changes: 116 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
const kCode = Symbol('code');
const messages = new Map();

const {
UV_EAI_MEMORY,
UV_EAI_NODATA,
UV_EAI_NONAME
} = process.binding('uv');
const { defineProperty } = Object;

// Lazily loaded
Expand All @@ -22,6 +27,14 @@ function lazyUtil() {
return util_;
}

var internalUtil = null;
function lazyInternalUtil() {
if (!internalUtil) {
internalUtil = require('internal/util');
}
return internalUtil;
}

function makeNodeError(Base) {
return class NodeError extends Base {
constructor(key, ...args) {
Expand Down Expand Up @@ -125,7 +138,110 @@ function E(sym, val) {
messages.set(sym, typeof val === 'function' ? val : String(val));
}

/**
* This used to be util._errnoException().
*
* @param {number} err - A libuv error number
* @param {string} syscall
* @param {string} [original]
* @returns {Error}
*/
function errnoException(err, syscall, original) {
// TODO(joyeecheung): We have to use the type-checked
// getSystemErrorName(err) to guard against invalid arguments from users.
// This can be replaced with [ code ] = errmap.get(err) when this method
// is no longer exposed to user land.
const code = lazyUtil().getSystemErrorName(err);
const message = original ?
`${syscall} ${code} ${original}` : `${syscall} ${code}`;

const ex = new Error(message);
// TODO(joyeecheung): errno is supposed to err, like in uvException
ex.code = ex.errno = code;
ex.syscall = syscall;

Error.captureStackTrace(ex, errnoException);
return ex;
}

/**
* This used to be util._exceptionWithHostPort().
*
* @param {number} err - A libuv error number
* @param {string} syscall
* @param {string} address
* @param {number} [port]
* @param {string} [additional]
* @returns {Error}
*/
function exceptionWithHostPort(err, syscall, address, port, additional) {
// TODO(joyeecheung): We have to use the type-checked
// getSystemErrorName(err) to guard against invalid arguments from users.
// This can be replaced with [ code ] = errmap.get(err) when this method
// is no longer exposed to user land.
const code = lazyUtil().getSystemErrorName(err);
let details = '';
if (port && port > 0) {
details = ` ${address}:${port}`;
} else if (address) {
details = ` ${address}`;
}
if (additional) {
details += ` - Local (${additional})`;
}

const ex = new Error(`${syscall} ${code}${details}`);
// TODO(joyeecheung): errno is supposed to err, like in uvException
ex.code = ex.errno = code;
ex.syscall = syscall;
ex.address = address;
if (port) {
ex.port = port;
}

Error.captureStackTrace(ex, exceptionWithHostPort);
return ex;
}

/**
* @param {number|string} err - A libuv error number or a c-ares error code
* @param {string} syscall
* @param {string} [hostname]
* @returns {Error}
*/
function dnsException(err, syscall, hostname) {
const ex = new Error();
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
if (err === UV_EAI_MEMORY ||
err === UV_EAI_NODATA ||
err === UV_EAI_NONAME) {
err = 'ENOTFOUND'; // Fabricated error name.
}
if (typeof err === 'string') { // c-ares error code.
const errHost = hostname ? ` ${hostname}` : '';
ex.message = `${syscall} ${err}${errHost}`;
// TODO(joyeecheung): errno is supposed to be a number, like in uvException
ex.code = ex.errno = err;
ex.syscall = syscall;
} else { // libuv error number
const code = lazyInternalUtil().getSystemErrorName(err);
ex.message = `${syscall} ${code}`;
// TODO(joyeecheung): errno is supposed to be err, like in uvException
ex.code = ex.errno = code;
ex.syscall = syscall;
}
if (hostname) {
ex.hostname = hostname;
}
Error.captureStackTrace(ex, dnsException);
return ex;
}

module.exports = exports = {
dnsException,
errnoException,
exceptionWithHostPort,
message,
Error: makeNodeError(Error),
TypeError: makeNodeError(TypeError),
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ class Http2Stream extends Duplex {
req.async = false;
const err = createWriteReq(req, handle, data, encoding);
if (err)
return this.destroy(util._errnoException(err, 'write', req.error), cb);
return this.destroy(errors.errnoException(err, 'write', req.error), cb);
trackWriteState(this, req.bytes);
}

Expand Down Expand Up @@ -1690,7 +1690,7 @@ class Http2Stream extends Duplex {
}
const err = handle.writev(req, chunks);
if (err)
return this.destroy(util._errnoException(err, 'write', req.error), cb);
return this.destroy(errors.errnoException(err, 'write', req.error), cb);
trackWriteState(this, req.bytes);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const errors = require('internal/errors');
const util = require('util');
const constants = process.binding('constants').os.signals;

Expand Down Expand Up @@ -180,7 +181,7 @@ function setupKillAndExit() {
}

if (err)
throw util._errnoException(err, 'kill');
throw errors.errnoException(err, 'kill');

return true;
};
Expand Down Expand Up @@ -211,7 +212,7 @@ function setupSignalHandlers() {
const err = wrap.start(signum);
if (err) {
wrap.close();
throw util._errnoException(err, 'uv_signal_start');
throw errors.errnoException(err, 'uv_signal_start');
}

signalWraps[type] = wrap;
Expand Down
4 changes: 2 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const dns = require('dns');
// reasons it's lazy loaded.
var cluster = null;

const errnoException = util._errnoException;
const exceptionWithHostPort = util._exceptionWithHostPort;
const errnoException = errors.errnoException;
const exceptionWithHostPort = errors.exceptionWithHostPort;

function noop() {}

Expand Down
8 changes: 3 additions & 5 deletions lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

'use strict';

const util = require('util');
const { inherits, _extend } = require('util');
const net = require('net');
const { TTY, isTTY } = process.binding('tty_wrap');
const { inherits } = util;
const errnoException = util._errnoException;
const errors = require('internal/errors');
const readline = require('readline');

Expand All @@ -40,7 +38,7 @@ function ReadStream(fd, options) {
if (fd >> 0 !== fd || fd < 0)
throw new errors.RangeError('ERR_INVALID_FD', fd);

options = util._extend({
options = _extend({
highWaterMark: 0,
readable: true,
writable: false,
Expand Down Expand Up @@ -99,7 +97,7 @@ WriteStream.prototype._refreshSize = function() {
var winSize = new Array(2);
var err = this._handle.getWindowSize(winSize);
if (err) {
this.emit('error', errnoException(err, 'getWindowSize'));
this.emit('error', errors.errnoException(err, 'getWindowSize'));
return;
}
var newCols = winSize[0];
Expand Down
Loading