From 5e140b33e58bd0ac6779fb0cb635dd51e1a27289 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 13 Mar 2013 15:36:52 -0700 Subject: [PATCH] Revert "fs: Missing cb errors are deprecated, not a throw" This reverts commits 6bd8b7e5405e1cdc9f56214f5f6b741806c32e5f and fa05e8a2706e20a191942fe2b2273481605a1f14. --- doc/api/fs.markdown | 23 ++++++++++++++---- lib/fs.js | 34 ++++++++------------------- test/simple/test-fs-readfile-error.js | 11 +-------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index e7a562d17a..29d3aa3339 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -63,11 +63,26 @@ Relative path to filename can be used, remember however that this path will be relative to `process.cwd()`. Most fs functions let you omit the callback argument. If you do, a default -callback is used that ignores errors, but prints a deprecation -warning. +callback is used that rethrows errors. To get a trace to the original call +site, set the NODE_DEBUG environment variable: -**IMPORTANT**: Omitting the callback is deprecated. v0.12 will throw the -errors as exceptions. + $ cat script.js + 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. (/path/to/script.js:5:1) + ## fs.rename(oldPath, newPath, [callback]) diff --git a/lib/fs.js b/lib/fs.js index 49bb027376..3d37a648a7 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -59,36 +59,22 @@ var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG); function rethrow() { // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and // is fairly slow to generate. - var callback; if (DEBUG) { var backtrace = new Error; - callback = debugCallback; - } else - callback = missingCallback; - - return callback; - - function debugCallback(err) { - if (err) { - backtrace.message = err.message; - err = backtrace; - missingCallback(err); - } + return function(err) { + if (err) { + backtrace.message = err.message; + err = backtrace; + throw err; + } + }; } - function missingCallback(err) { + return function(err) { if (err) { - if (process.throwDeprecation) - 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); - } + throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs } - } + }; } function maybeCallback(cb) { diff --git a/test/simple/test-fs-readfile-error.js b/test/simple/test-fs-readfile-error.js index 97d2f06a61..72e1e2e7fb 100644 --- a/test/simple/test-fs-readfile-error.js +++ b/test/simple/test-fs-readfile-error.js @@ -28,7 +28,7 @@ var callbacks = 0; function test(env, cb) { 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 || {} }; exec(execPath, options, function(err, stdout, stderr) { assert(err); @@ -53,12 +53,3 @@ test({ NODE_DEBUG: 'fs' }, function(data) { process.on('exit', function() { 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'); -})();