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

lib,fs: use process.emitWarning instead of internal print dep warning #8166

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fs: use process.emitWarning to print deprecation warning
As an alternative to #6413, use
process.emitWarning() instead of the internal printDeprecationMessage
in order to avoid use of an internal only API.
  • Loading branch information
jasnell committed Sep 2, 2016
commit 09d97e9e2e1421c6153c99f8b02e6f26f3dd04e5
24 changes: 15 additions & 9 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const isWindows = process.platform === 'win32';

const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;
const printDeprecation = require('internal/util').printDeprecationMessage;

Copy link
Member

@ChALkeR ChALkeR Aug 30, 2016

Choose a reason for hiding this comment

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

Could you leave require('internal/util'); here so this won't become suddenly re-evaluatable in v7? Or we might be forced to do another round of deprecation…

That line could be removed when something else will land that requires internal, hopefully in time for v7.

Upd: not needed anymore, as #6749 landed.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are several other open PRs that move bits to internal/fs.js that would cover this requirement.

Copy link
Member

Choose a reason for hiding this comment

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

Only if those land before this one =).

Copy link
Member Author

Choose a reason for hiding this comment

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

@ChALkeR ... #6749 landed just now, which adds a ref to internal/fs

Copy link
Member

Choose a reason for hiding this comment

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

Yay!
That discards my previous comments in this subthread =).

function throwOptionsError(options) {
throw new TypeError('Expected options to be either an object or a string, ' +
Expand Down Expand Up @@ -613,10 +612,14 @@ var readWarned = false;
fs.read = function(fd, buffer, offset, length, position, callback) {
if (!(buffer instanceof Buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
readWarned = printDeprecation('fs.read\'s legacy String interface ' +
'is deprecated. Use the Buffer API as ' +
'mentioned in the documentation instead.',
readWarned);
if (!readWarned) {
readWarned = true;
process.emitWarning(
'fs.read\'s legacy String interface is deprecated. Use the Buffer ' +
'API as mentioned in the documentation instead.',
'DeprecationWarning');
}

const cb = arguments[4];
const encoding = arguments[3];

Expand Down Expand Up @@ -673,10 +676,13 @@ fs.readSync = function(fd, buffer, offset, length, position) {

if (!(buffer instanceof Buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
readSyncWarned = printDeprecation('fs.readSync\'s legacy String interface' +
'is deprecated. Use the Buffer API as ' +
'mentioned in the documentation instead.',
readSyncWarned);
if (!readSyncWarned) {
readSyncWarned = true;
process.emitWarning(
'fs.readSync\'s legacy String interface is deprecated. Use the ' +
'Buffer API as mentioned in the documentation instead.',
'DeprecationWarning');
}
legacy = true;
encoding = arguments[3];

Expand Down