From b36c726206eca78ae784c2b227d556a6dbc9935b Mon Sep 17 00:00:00 2001 From: Weijia Wang <381152119@qq.com> Date: Mon, 20 Nov 2017 17:13:50 +0800 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Joyee Cheung --- lib/_stream_readable.js | 2 +- lib/_stream_writable.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 8e38030da85e4b..01d886e6cab2eb 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -285,7 +285,7 @@ function chunkInvalid(state, chunk) { chunk !== undefined && !state.objectMode) { er = new errors.TypeError('ERR_INVALID_ARG_TYPE', - 'chunk', 'string/Buffer/Uint8Array'); + 'chunk', ['string', 'Buffer', 'Uint8Array']); } return er; } diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 1735fafb5f34d3..02481739250635 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -252,7 +252,8 @@ function validChunk(stream, state, chunk, cb) { } else if (typeof chunk !== 'string' && chunk !== undefined && !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) { stream.emit('error', er);