Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: moving internal helpers to internal module #2025

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('util');
const internalUtil = require('internal/util');
const debug = util.debuglog('child_process');
const constants = require('constants');

@@ -10,7 +11,7 @@ const Buffer = require('buffer').Buffer;
const Pipe = process.binding('pipe_wrap').Pipe;
const child_process = require('internal/child_process');

const errnoException = util._errnoException;
const errnoException = internalUtil._errnoException;
const _validateStdio = child_process._validateStdio;
const setupChannel = child_process.setupChannel;
const ChildProcess = exports.ChildProcess = child_process.ChildProcess;
5 changes: 3 additions & 2 deletions lib/dgram.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
const assert = require('assert');
const Buffer = require('buffer').Buffer;
const util = require('util');
const internalUtil = require('internal/util');
const events = require('events');
const constants = require('constants');

@@ -17,8 +18,8 @@ const BIND_STATE_BOUND = 2;
var cluster = null;
var dns = null;

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

function lookup(address, family, callback) {
if (!dns)
3 changes: 2 additions & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

const net = require('net');
const util = require('util');
const internalUtil = require('internal/util');

const cares = process.binding('cares_wrap');
const uv = process.binding('uv');
@@ -27,7 +28,7 @@ function errnoException(err, syscall, hostname) {
ex.errno = err;
ex.syscall = syscall;
} else {
ex = util._errnoException(err, syscall);
ex = internalUtil._errnoException(err, syscall);
}
if (hostname) {
ex.hostname = hostname;
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

const SlowBuffer = require('buffer').SlowBuffer;
const util = require('util');
const internalUtil = require('internal/util');
const pathModule = require('path');

const binding = process.binding('fs');
@@ -34,7 +35,7 @@ const O_WRONLY = constants.O_WRONLY || 0;
const isWindows = process.platform === 'win32';

const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this break graceful-fs again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would. It's probably better to add a test for this to prevent accidental breakage

const errnoException = util._errnoException;
const errnoException = internalUtil._errnoException;

function throwOptionsError(options) {
throw new TypeError('Expected options to be either an object or a string, ' +
3 changes: 2 additions & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ const EventEmitter = require('events').EventEmitter;
const net = require('net');
const dgram = require('dgram');
const util = require('util');
const internalUtil = require('internal/util');
const constants = require('constants');
const assert = require('assert');

@@ -18,7 +19,7 @@ const TCP = process.binding('tcp_wrap').TCP;
const UDP = process.binding('udp_wrap').UDP;
const SocketList = require('internal/socket_list');

const errnoException = util._errnoException;
const errnoException = internalUtil._errnoException;
const SocketListSend = SocketList.SocketListSend;
const SocketListReceive = SocketList.SocketListReceive;

41 changes: 41 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const uv = process.binding('uv');

exports.printDeprecationMessage = function(msg, warned) {
if (process.noDeprecation)
return true;
@@ -40,3 +42,42 @@ exports.deprecate = function(fn, msg) {

return deprecated;
};

exports._errnoException = function(err, syscall, original) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is going into an internal module, it doesn't need the underscore name.

Also, can we name the function (exports.errnoException = function errnoException(..) {) so we don't have to deal with exports.errnoException() below?

const errname = uv.errname(err);
var message = syscall + ' ' + errname;

if (original)
message += ' ' + original;

const e = new Error(message);
e.code = errname;
e.errno = errname;
e.syscall = syscall;

return e;
};


exports._exceptionWithHostPort = function(err, syscall, address, port, extra) {
var details;

if (port && port > 0) {
details = address + ':' + port;
} else {
details = address;
}

if (extra) {
details += ' - Local (' + extra + ')';
}

const ex = exports._errnoException(err, syscall, details);

ex.address = address;
if (port) {
ex.port = port;
}

return ex;
};
5 changes: 3 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const events = require('events');
const stream = require('stream');
const timers = require('timers');
const util = require('util');
const internalUtil = require('internal/util');
const assert = require('assert');
const cares = process.binding('cares_wrap');
const uv = process.binding('uv');
@@ -19,8 +20,8 @@ const WriteWrap = process.binding('stream_wrap').WriteWrap;


var cluster;
const errnoException = util._errnoException;
const exceptionWithHostPort = util._exceptionWithHostPort;
const errnoException = internalUtil._errnoException;
const exceptionWithHostPort = internalUtil._exceptionWithHostPort;

function noop() {}

3 changes: 2 additions & 1 deletion lib/tty.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const util = require('util');
const internalUtil = require('internal/util');
const net = require('net');
const TTY = process.binding('tty_wrap').TTY;
const isTTY = process.binding('tty_wrap').isTTY;
const inherits = util.inherits;
const errnoException = util._errnoException;
const errnoException = internalUtil._errnoException;


exports.isatty = function(fd) {
41 changes: 6 additions & 35 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const uv = process.binding('uv');
const Buffer = require('buffer').Buffer;
const Debug = require('vm').runInDebugContext('Debug');
const internalUtil = require('internal/util');
@@ -806,38 +805,10 @@ exports.pump = exports.deprecate(function(readStream, writeStream, callback) {
}, 'util.pump(): Use readableStream.pipe() instead');


exports._errnoException = function(err, syscall, original) {
var errname = uv.errname(err);
var message = syscall + ' ' + errname;
if (original)
message += ' ' + original;
var e = new Error(message);
e.code = errname;
e.errno = errname;
e.syscall = syscall;
return e;
};


exports._exceptionWithHostPort = function(err,
syscall,
address,
port,
additional) {
var details;
if (port && port > 0) {
details = address + ':' + port;
} else {
details = address;
}
exports._errnoException = internalUtil.deprecate(
internalUtil._errnoException,
'util._errnoException is deprecated.');

if (additional) {
details += ' - Local (' + additional + ')';
}
var ex = exports._errnoException(err, syscall, details);
ex.address = address;
if (port) {
ex.port = port;
}
return ex;
};
exports._exceptionWithHostPort = internalUtil.deprecate(
internalUtil._exceptionWithHostPort,
'util._exceptionWithHostPort is deprecated.');