Revert "fs: Missing cb errors are deprecated, not a throw"
This reverts commits 6bd8b7e5405e1cdc9f56214f5f6b741806c32e5f and fa05e8a2706e20a191942fe2b2273481605a1f14.
This commit is contained in:
parent
5917828622
commit
5e140b33e5
@ -63,11 +63,26 @@ Relative path to filename can be used, remember however that this path will be
|
|||||||
relative to `process.cwd()`.
|
relative to `process.cwd()`.
|
||||||
|
|
||||||
Most fs functions let you omit the callback argument. If you do, a default
|
Most fs functions let you omit the callback argument. If you do, a default
|
||||||
callback is used that ignores errors, but prints a deprecation
|
callback is used that rethrows errors. To get a trace to the original call
|
||||||
warning.
|
site, set the NODE_DEBUG environment variable:
|
||||||
|
|
||||||
**IMPORTANT**: Omitting the callback is deprecated. v0.12 will throw the
|
$ cat script.js
|
||||||
errors as exceptions.
|
function bad() {
|
||||||
|
require('fs').readFile('/');
|
||||||
|
}
|
||||||
|
bad();
|
||||||
|
|
||||||
|
$ env NODE_DEBUG=fs node script.js
|
||||||
|
fs.js:66
|
||||||
|
throw err;
|
||||||
|
^
|
||||||
|
Error: EISDIR, read
|
||||||
|
at rethrow (fs.js:61:21)
|
||||||
|
at maybeCallback (fs.js:79:42)
|
||||||
|
at Object.fs.readFile (fs.js:153:18)
|
||||||
|
at bad (/path/to/script.js:2:17)
|
||||||
|
at Object.<anonymous> (/path/to/script.js:5:1)
|
||||||
|
<etc.>
|
||||||
|
|
||||||
|
|
||||||
## fs.rename(oldPath, newPath, [callback])
|
## fs.rename(oldPath, newPath, [callback])
|
||||||
|
24
lib/fs.js
24
lib/fs.js
@ -59,36 +59,22 @@ var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
|
|||||||
function rethrow() {
|
function rethrow() {
|
||||||
// Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
|
// Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
|
||||||
// is fairly slow to generate.
|
// is fairly slow to generate.
|
||||||
var callback;
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
var backtrace = new Error;
|
var backtrace = new Error;
|
||||||
callback = debugCallback;
|
return function(err) {
|
||||||
} else
|
|
||||||
callback = missingCallback;
|
|
||||||
|
|
||||||
return callback;
|
|
||||||
|
|
||||||
function debugCallback(err) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
backtrace.message = err.message;
|
backtrace.message = err.message;
|
||||||
err = backtrace;
|
err = backtrace;
|
||||||
missingCallback(err);
|
throw err;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function missingCallback(err) {
|
return function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (process.throwDeprecation)
|
|
||||||
throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
|
throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
|
||||||
else if (!process.noDeprecation) {
|
|
||||||
var msg = 'fs: missing callback ' + (err.stack || err.message);
|
|
||||||
if (process.traceDeprecation)
|
|
||||||
console.trace(msg);
|
|
||||||
else
|
|
||||||
console.error(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeCallback(cb) {
|
function maybeCallback(cb) {
|
||||||
|
@ -28,7 +28,7 @@ var callbacks = 0;
|
|||||||
|
|
||||||
function test(env, cb) {
|
function test(env, cb) {
|
||||||
var filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js');
|
var filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js');
|
||||||
var execPath = process.execPath + ' --throw-deprecation ' + filename;
|
var execPath = process.execPath + ' ' + filename;
|
||||||
var options = { env: env || {} };
|
var options = { env: env || {} };
|
||||||
exec(execPath, options, function(err, stdout, stderr) {
|
exec(execPath, options, function(err, stdout, stderr) {
|
||||||
assert(err);
|
assert(err);
|
||||||
@ -53,12 +53,3 @@ test({ NODE_DEBUG: 'fs' }, function(data) {
|
|||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
assert.equal(callbacks, 2);
|
assert.equal(callbacks, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
(function() {
|
|
||||||
console.error('the warnings are normal here.');
|
|
||||||
// just make sure that this doesn't crash the process.
|
|
||||||
var fs = require('fs');
|
|
||||||
fs.readFile(__dirname);
|
|
||||||
fs.readdir(__filename);
|
|
||||||
fs.unlink('gee-i-sure-hope-this-file-isnt-important-or-existing');
|
|
||||||
})();
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user