fs: migrate errors to internal/errors
Throw ERR_INVALID_ARG_TYPE when validating arguments passed to WriteStream.prototype._write. Refs: https://github.com/nodejs/node/issues/17709 PR-URL: https://github.com/nodejs/node/pull/17719 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
ae2bed9938
commit
8599465d33
@ -2554,8 +2554,13 @@ WriteStream.prototype.open = function() {
|
|||||||
|
|
||||||
|
|
||||||
WriteStream.prototype._write = function(data, encoding, cb) {
|
WriteStream.prototype._write = function(data, encoding, cb) {
|
||||||
if (!(data instanceof Buffer))
|
if (!(data instanceof Buffer)) {
|
||||||
return this.emit('error', new Error('Invalid data'));
|
const err = new errors.TypeError('ERR_INVALID_ARG_TYPE',
|
||||||
|
'data',
|
||||||
|
'Buffer',
|
||||||
|
data);
|
||||||
|
return this.emit('error', err);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof this.fd !== 'number') {
|
if (typeof this.fd !== 'number') {
|
||||||
return this.once('open', function() {
|
return this.once('open', function() {
|
||||||
|
@ -49,3 +49,16 @@ common.refreshTmpDir();
|
|||||||
});
|
});
|
||||||
stream.destroy();
|
stream.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Throws if data is not of type Buffer.
|
||||||
|
{
|
||||||
|
const stream = fs.createWriteStream(file);
|
||||||
|
common.expectsError(() => {
|
||||||
|
stream._write(42, null, function() {});
|
||||||
|
}, {
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "data" argument must be of type Buffer. Received type number'
|
||||||
|
});
|
||||||
|
stream.destroy();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user