const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;
+function throwOptionsError(options) {
+ throw new TypeError('Expected options to be either an object or a string, ' +
+ 'but got ' + typeof options + ' instead');
+}
function rethrow() {
// Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
fs.readFile = function(path, options, callback_) {
var callback = maybeCallback(arguments[arguments.length - 1]);
- if (!options || typeof options === 'function')
+ if (!options || typeof options === 'function') {
options = { encoding: null, flag: 'r' };
- else if (typeof options === 'string')
+ } else if (typeof options === 'string') {
options = { encoding: options, flag: 'r' };
- else if (typeof options !== 'object')
- throw new TypeError('Bad arguments');
+ } else if (typeof options !== 'object') {
+ throwOptionsError(options);
+ }
var encoding = options.encoding;
assertEncoding(encoding);
} else if (typeof options === 'string') {
options = { encoding: options, flag: 'r' };
} else if (typeof options !== 'object') {
- throw new TypeError('Bad arguments');
+ throwOptionsError(options);
}
var encoding = options.encoding;
} else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'w' };
} else if (typeof options !== 'object') {
- throw new TypeError('Bad arguments');
+ throwOptionsError(options);
}
assertEncoding(options.encoding);
} else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'w' };
} else if (typeof options !== 'object') {
- throw new TypeError('Bad arguments');
+ throwOptionsError(options);
}
assertEncoding(options.encoding);
} else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'a' };
} else if (typeof options !== 'object') {
- throw new TypeError('Bad arguments');
+ throwOptionsError(options);
}
if (!options.flag)
} else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'a' };
} else if (typeof options !== 'object') {
- throw new TypeError('Bad arguments');
+ throwOptionsError(options);
}
if (!options.flag)
options = util._extend({ flag: 'a' }, options);