From c6b6c92185316e13738e6fa931fdd5303e381e46 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 19 Mar 2018 13:33:46 +0100 Subject: lib: always show ERR_INVALID_ARG_TYPE received part This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Joyee Cheung Reviewed-By: Anna Henningsen --- lib/internal/encoding.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/internal/encoding.js') diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 9cd47f861f..ae874c530c 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -51,7 +51,7 @@ function validateDecoder(obj) { function validateArgument(prop, expected, propName, expectedName) { if (typeof prop !== expected) - throw new ERR_INVALID_ARG_TYPE(propName, expectedName); + throw new ERR_INVALID_ARG_TYPE(propName, expectedName, prop); } const CONVERTER_FLAGS_FLUSH = 0x1; @@ -391,7 +391,8 @@ function makeTextDecoderICU() { input = lazyBuffer().from(input); } else if (!isArrayBufferView(input)) { throw new ERR_INVALID_ARG_TYPE('input', - ['ArrayBuffer', 'ArrayBufferView']); + ['ArrayBuffer', 'ArrayBufferView'], + input); } validateArgument(options, 'object', 'options', 'Object'); @@ -460,7 +461,8 @@ function makeTextDecoderJS() { input.byteLength); } else { throw new ERR_INVALID_ARG_TYPE('input', - ['ArrayBuffer', 'ArrayBufferView']); + ['ArrayBuffer', 'ArrayBufferView'], + input); } validateArgument(options, 'object', 'options', 'Object'); -- cgit v1.2.3