stream: improve the error message of ERR_INVALID_ARG_TYPE

The `expected` argument of `ERR_INVALID_ARG_TYPE` can be an
array, which is better than a single string.

PR-URL: https://github.com/nodejs/node/pull/17145
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Weijia Wang 2017-11-20 17:13:50 +08:00 committed by James M Snell
parent 8f2c366bb2
commit 0a948b903d
2 changed files with 3 additions and 2 deletions

View File

@ -285,7 +285,7 @@ function chunkInvalid(state, chunk) {
chunk !== undefined && chunk !== undefined &&
!state.objectMode) { !state.objectMode) {
er = new errors.TypeError('ERR_INVALID_ARG_TYPE', er = new errors.TypeError('ERR_INVALID_ARG_TYPE',
'chunk', 'string/Buffer/Uint8Array'); 'chunk', ['string', 'Buffer', 'Uint8Array']);
} }
return er; return er;
} }

View File

@ -252,7 +252,8 @@ function validChunk(stream, state, chunk, cb) {
} else if (typeof chunk !== 'string' && } else if (typeof chunk !== 'string' &&
chunk !== undefined && chunk !== undefined &&
!state.objectMode) { !state.objectMode) {
er = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'chunk', 'string/buffer'); er = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'chunk',
['string', 'Buffer']);
} }
if (er) { if (er) {
stream.emit('error', er); stream.emit('error', er);