Skip to content

Commit

Permalink
lib: Improving deprecation messages
Browse files Browse the repository at this point in the history
Prefixing all the deprecation messages with `[node]` so that the users
 will know where the message comes from.
  • Loading branch information
thefourtheye committed Jun 4, 2015
1 parent ac6ad25 commit 08e57b4
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,4 @@ OutgoingMessage.prototype.flushHeaders = function() {

OutgoingMessage.prototype.flush = util.deprecate(function() {
this.flushHeaders();
}, 'flush is deprecated. Use flushHeaders instead.');
}, '[node] OutgoingMessage.flush is deprecated. Use flushHeaders instead.');
2 changes: 1 addition & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ WritableState.prototype.getBuffer = function writableStateGetBuffer() {
Object.defineProperty(WritableState.prototype, 'buffer', {
get: util.deprecate(function() {
return this.getBuffer();
}, '_writableState.buffer is deprecated. Use ' +
}, '[node] _writableState.buffer is deprecated. Use ' +
'_writableState.getBuffer() instead.')
});

Expand Down
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ Buffer.prototype.get = util.deprecate(function get(offset) {
if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range');
return this[offset];
}, '.get() is deprecated. Access using array indexes instead.');
}, '[node] Buffer.get() is deprecated. Access using array indexes instead.');


// XXX remove in v0.13
Expand All @@ -469,7 +469,7 @@ Buffer.prototype.set = util.deprecate(function set(offset, v) {
if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range');
return this[offset] = v;
}, '.set() is deprecated. Set using array indexes instead.');
}, '[node] Buffer.set() is deprecated. Set using array indexes instead.');


// TODO(trevnorris): fix these checks to follow new standard
Expand Down
2 changes: 1 addition & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ var _deprecatedCustomFds = util.deprecate(function(options) {
options.stdio = options.customFds.map(function(fd) {
return fd === -1 ? 'pipe' : fd;
});
}, 'child_process: customFds option is deprecated, use stdio instead.');
}, '[node] child_process.customFds option is deprecated, use stdio instead.');

function _convertCustomFds(options) {
if (options && options.customFds && !options.stdio) {
Expand Down
6 changes: 4 additions & 2 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,10 @@ function filterDuplicates(names) {
// Legacy API
exports.__defineGetter__('createCredentials', util.deprecate(function() {
return require('tls').createSecureContext;
}, 'createCredentials() is deprecated, use tls.createSecureContext instead'));
}, '[node] crypto.createCredentials() is deprecated, ' +
'use tls.createSecureContext instead'));

exports.__defineGetter__('Credentials', util.deprecate(function() {
return require('tls').SecureContext;
}, 'Credentials is deprecated, use tls.createSecureContext instead'));
}, '[node] crypto.Credentials is deprecated, ' +
'use tls.createSecureContext instead'));
4 changes: 2 additions & 2 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Client.prototype.request = function(method, path, headers) {
};

exports.Client = util.deprecate(Client,
'http.Client will be removed soon. Do not use it.');
'[node] http.Client will be removed soon. Do not use it.');

exports.createClient = util.deprecate(function(port, host) {
return new Client(port, host);
}, 'http.createClient is deprecated. Use `http.request` instead.');
}, '[node] http.createClient is deprecated. Use `http.request` instead.');
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function tryExtensions(p, exts) {


const noopDeprecateRequireDot = util.deprecate(function() {},
'warning: require(\'.\') resolved outside the package directory. ' +
'[node] warning: require(\'.\') resolved outside the package directory. ' +
'This functionality is deprecated and will be removed soon.');


Expand Down
7 changes: 4 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,11 @@ function Server(options, connectionListener) {
return null;
}
return self._connections;
}, 'connections property is deprecated. Use getConnections() method'),
}, '[node] Server.connections property is deprecated. ' +
'Use Server.getConnections() method'),
set: util.deprecate(function(val) {
return (self._connections = val);
}, 'connections property is deprecated. Use getConnections() method'),
}, '[node] Server.connections property is deprecated.'),
configurable: true, enumerable: false
});

Expand Down Expand Up @@ -1498,7 +1499,7 @@ function emitCloseNT(self) {

Server.prototype.listenFD = util.deprecate(function(fd, type) {
return this.listen({ fd: fd });
}, 'listenFD is deprecated. Use listen({fd: <number>}).');
}, '[node] Server.listenFD is deprecated. Use Server.listen({fd: <number>}).');

Server.prototype._setupSlave = function(socketList) {
this._usingSlaves = true;
Expand Down
3 changes: 2 additions & 1 deletion lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ exports.tmpDir = exports.tmpdir;

exports.getNetworkInterfaces = util.deprecate(function() {
return exports.networkInterfaces();
}, 'getNetworkInterfaces is now called `os.networkInterfaces`.');
}, '[node] os.getNetworkInterfaces is deprecated. ' +
'Use `os.networkInterfaces` instead.');

exports.EOL = isWindows ? '\r\n' : '\n';

Expand Down
3 changes: 2 additions & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,8 @@ function codePointAt(str, index) {
return code;
}
exports.codePointAt = util.deprecate(codePointAt,
'codePointAt() is deprecated. Use String.prototype.codePointAt');
'[node] readline.codePointAt is deprecated. ' +
'Use String.prototype.codePointAt instead');


/**
Expand Down
9 changes: 5 additions & 4 deletions lib/smalloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ const smalloc = require('internal/smalloc');
const deprecate = require('util').deprecate;

exports.alloc =
deprecate(smalloc.alloc, 'smalloc.alloc: Deprecated, use typed arrays');
deprecate(smalloc.alloc,
'[node] smalloc.alloc is deprecated, use typed arrays');

exports.copyOnto =
deprecate(smalloc.copyOnto,
'smalloc.copyOnto: Deprecated, use typed arrays');
'[node] smalloc.copyOnto is deprecated, use typed arrays');

exports.dispose =
deprecate(smalloc.dispose,
'smalloc.dispose: Deprecated, use typed arrays');
'[node] smalloc.dispose is deprecated, use typed arrays');

exports.hasExternalData =
deprecate(smalloc.hasExternalData,
'smalloc.hasExternalData: Deprecated, use typed arrays');
'[node] smalloc.hasExternalData is deprecated, use typed arrays');

Object.defineProperty(exports, 'kMaxLength', {
enumerable: true, value: smalloc.kMaxLength, writable: false
Expand Down
2 changes: 1 addition & 1 deletion lib/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ const util = require('util');

const setExports = util.deprecate(function() {
module.exports = util;
}, 'sys is deprecated. Use util instead.');
}, '[node] sys module is deprecated. Use util module instead.');

setExports();
3 changes: 2 additions & 1 deletion lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ exports.setRawMode = util.deprecate(function(flag) {
throw new Error('can\'t set raw mode on non-tty');
}
process.stdin.setRawMode(flag);
}, 'tty.setRawMode: Use `process.stdin.setRawMode()` instead.');
}, '[node] tty.setRawMode is depreacted. ' +
'Use `process.stdin.setRawMode()` instead.');


function ReadStream(fd, options) {
Expand Down

0 comments on commit 08e57b4

Please sign in to comment.