errors: improve the description of ERR_INVALID_ARG_VALUE

- Allow user to customize why the argument is invalid
- Display the argument with util.inspect so null bytes can be
  displayed properly.

PR-URL: https://github.com/nodejs/node/pull/18358
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
This commit is contained in:
Joyee Cheung committed 2018-01-29 13:41:40 +08:00
1 parent 368517c0dc
commit 3ec79216f9
2 files changed
+35 -13

No files matched your search

+12 -2
View File
@@ -351,10 +351,20 @@ assert.strictEqual(
}
{
const error = new errors.Error('ERR_INVALID_ARG_VALUE', 'foo', 'bar');
const error = new errors.Error('ERR_INVALID_ARG_VALUE', 'foo', '\u0000bar');
assert.strictEqual(
error.message,
'The value "bar" is invalid for argument "foo"'
'The argument \'foo\' is invalid. Received \'\\u0000bar\''
);
}
{
const error = new errors.Error(
'ERR_INVALID_ARG_VALUE',
'foo', { a: 1 }, 'must have property \'b\'');
assert.strictEqual(
error.message,
'The argument \'foo\' must have property \'b\'. Received { a: 1 }'
);
}