mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
lib: throw a special error in internal/assert
Instead of using the public AssertionError, use a simplified error that describes potential causes of these assertions and suggests the user to open an issue. PR-URL: https://github.com/nodejs/node/pull/26635 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
1 parent
237d9f9716
commit
b9f1e57201
12 files changed
+100
-28
No files matched your search
@@ -1,17 +1,13 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
// This tests that the internal assert module works as expected.
|
||||
// The failures are tested in test/message.
|
||||
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const internalAssert = require('internal/assert');
|
||||
|
||||
// Should not throw.
|
||||
internalAssert(true);
|
||||
internalAssert(true, 'fhqwhgads');
|
||||
|
||||
assert.throws(() => { internalAssert(false); }, assert.AssertionError);
|
||||
assert.throws(() => { internalAssert(false, 'fhqwhgads'); },
|
||||
{ code: 'ERR_ASSERTION', message: 'fhqwhgads' });
|
||||
assert.throws(() => { internalAssert.fail('fhqwhgads'); },
|
||||
{ code: 'ERR_ASSERTION', message: 'fhqwhgads' });
|
||||
@@ -50,12 +50,10 @@ errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error);
|
||||
}
|
||||
|
||||
{
|
||||
assert.throws(
|
||||
common.expectsInternalAssertion(
|
||||
() => new errors.codes.TEST_ERROR_1(),
|
||||
{
|
||||
message: 'Code: TEST_ERROR_1; The provided arguments ' +
|
||||
'length (0) does not match the required ones (1).'
|
||||
}
|
||||
'Code: TEST_ERROR_1; The provided arguments ' +
|
||||
'length (0) does not match the required ones (1).'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,12 +78,9 @@ common.expectsError(
|
||||
assert.throws(() => tls.createServer({ ticketKeys: Buffer.alloc(0) }),
|
||||
/TypeError: Ticket keys length must be 48 bytes/);
|
||||
|
||||
common.expectsError(
|
||||
common.expectsInternalAssertion(
|
||||
() => tls.createSecurePair({}),
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
message: 'context.context must be a NativeSecureContext'
|
||||
}
|
||||
'context.context must be a NativeSecureContext'
|
||||
);
|
||||
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user