@@ -77,7 +77,6 @@ const { kMaxLength } = require('buffer');
77
77
78
78
const isWindows = process . platform === 'win32' ;
79
79
80
- const DEBUG = process . env . NODE_DEBUG && / f s / . test ( process . env . NODE_DEBUG ) ;
81
80
const errnoException = errors . errnoException ;
82
81
83
82
let truncateWarn = true ;
@@ -106,46 +105,17 @@ function handleErrorFromBinding(ctx) {
106
105
}
107
106
}
108
107
109
- // TODO(joyeecheung): explore how the deprecation could be solved via linting
110
- // rules. See https://github.com/nodejs/node/pull/12976
111
- function rethrow ( ) {
112
- process . emitWarning (
113
- 'Calling an asynchronous function without callback is deprecated.' ,
114
- 'DeprecationWarning' , 'DEP0013' , rethrow
115
- ) ;
116
-
117
- // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
118
- // is fairly slow to generate.
119
- if ( DEBUG ) {
120
- var backtrace = new Error ( ) ;
121
- return function ( err ) {
122
- if ( err ) {
123
- backtrace . stack = `${ err . name } : ${ err . message } ` +
124
- backtrace . stack . substr ( backtrace . name . length ) ;
125
- throw backtrace ;
126
- }
127
- } ;
128
- }
129
-
130
- return function ( err ) {
131
- if ( err ) {
132
- throw err ; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
133
- }
134
- } ;
135
- }
136
-
137
108
function maybeCallback ( cb ) {
138
- return typeof cb === 'function' ? cb : rethrow ( ) ;
109
+ if ( typeof cb === 'function' )
110
+ return cb ;
111
+
112
+ throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
139
113
}
140
114
141
115
// Ensure that callbacks run in the global context. Only use this function
142
116
// for callbacks that are passed to the binding layer, callbacks that are
143
117
// invoked from JS already run in the proper scope.
144
118
function makeCallback ( cb ) {
145
- if ( cb === undefined ) {
146
- return rethrow ( ) ;
147
- }
148
-
149
119
if ( typeof cb !== 'function' ) {
150
120
throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
151
121
}
@@ -159,10 +129,6 @@ function makeCallback(cb) {
159
129
// an optimization, since the data passed back to the callback needs to be
160
130
// transformed anyway.
161
131
function makeStatsCallback ( cb ) {
162
- if ( cb === undefined ) {
163
- return rethrow ( ) ;
164
- }
165
-
166
132
if ( typeof cb !== 'function' ) {
167
133
throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
168
134
}
@@ -191,8 +157,6 @@ fs.access = function(path, mode, callback) {
191
157
if ( typeof mode === 'function' ) {
192
158
callback = mode ;
193
159
mode = fs . F_OK ;
194
- } else if ( typeof callback !== 'function' ) {
195
- throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
196
160
}
197
161
198
162
path = getPathFromURL ( path ) ;
@@ -218,16 +182,8 @@ fs.accessSync = function(path, mode) {
218
182
handleErrorFromBinding ( ctx ) ;
219
183
} ;
220
184
221
- // fs.exists never throws even when the arguments are invalid - if there is
222
- // a callback it would invoke it with false, otherwise it emits a warning
223
- // (see the comments of rethrow()).
224
- // This is to bring it inline with fs.existsSync, which never throws.
225
- // TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
226
185
fs . exists = function ( path , callback ) {
227
- if ( typeof callback !== 'function' ) {
228
- rethrow ( ) ;
229
- return ;
230
- }
186
+ maybeCallback ( callback ) ;
231
187
232
188
function suppressedCallback ( err ) {
233
189
callback ( err ? false : true ) ;
0 commit comments