mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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:
2 files changed
+35
-13
No files matched your search
@@ -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 }'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user