errors: validate input arguments

This makes sure the input arguments get validated so implementation
errors will be caught early. It also improves a couple of error
messages by providing more detailed information and fixes errors
detected by the new functionality. Besides that a error type got
simplified and tests got refactored.

PR-URL: https://github.com/nodejs/node/pull/19924
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater authored and James M Snell committed 2018-04-16 16:11:21 -07:00
1 parent cdacafc8bb
commit d28211ec3d
18 files changed
+215 -178

No files matched your search

+10 -12
View File
@@ -1,19 +1,17 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const errors = require('internal/errors');
const { AssertionError } = require('assert');
const { E, SystemError } = errors;
common.expectsError(
assert.throws(
() => { throw new errors.SystemError(); },
{
code: 'ERR_ASSERTION',
type: AssertionError,
message: 'An invalid error message key was used: undefined.'
name: 'TypeError',
message: 'Cannot read property \'match\' of undefined'
}
);
@@ -29,11 +27,11 @@ const { ERR_TEST } = errors.codes;
dest: '/str2'
};
common.expectsError(
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
type: SystemError,
name: 'SystemError [ERR_TEST]',
message: 'custom message: syscall_test returned ETEST (code message)' +
' /str => /str2',
info: ctx
@@ -49,11 +47,11 @@ const { ERR_TEST } = errors.codes;
path: Buffer.from('/buf'),
dest: '/str2'
};
common.expectsError(
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
type: SystemError,
name: 'SystemError [ERR_TEST]',
message: 'custom message: syscall_test returned ETEST (code message)' +
' /buf => /str2',
info: ctx
@@ -69,11 +67,11 @@ const { ERR_TEST } = errors.codes;
path: Buffer.from('/buf'),
dest: Buffer.from('/buf2')
};
common.expectsError(
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
type: SystemError,
name: 'SystemError [ERR_TEST]',
message: 'custom message: syscall_test returned ETEST (code message)' +
' /buf => /buf2',
info: ctx