diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-13 22:43:00 +0800 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-25 01:29:48 +0200 |
commit | b9f1e572017c146da66077331260bac0e60c0928 (patch) | |
tree | 94813ea917a49cb573d141f225922534770e6eed /test | |
parent | 237d9f97165da39d1e540699294cf2dc83bbc2d3 (diff) | |
download | android-node-v8-b9f1e572017c146da66077331260bac0e60c0928.tar.gz android-node-v8-b9f1e572017c146da66077331260bac0e60c0928.tar.bz2 android-node-v8-b9f1e572017c146da66077331260bac0e60c0928.zip |
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>
Diffstat (limited to 'test')
-rw-r--r-- | test/common/index.js | 14 | ||||
-rw-r--r-- | test/message/internal_assert.js | 7 | ||||
-rw-r--r-- | test/message/internal_assert.out | 15 | ||||
-rw-r--r-- | test/message/internal_assert_fail.js | 7 | ||||
-rw-r--r-- | test/message/internal_assert_fail.out | 16 | ||||
-rw-r--r-- | test/parallel/test-internal-assert.js | 10 | ||||
-rw-r--r-- | test/parallel/test-internal-errors.js | 8 | ||||
-rw-r--r-- | test/parallel/test-tls-basic-validations.js | 7 | ||||
-rw-r--r-- | test/sequential/test-fs-watch.js | 18 |
9 files changed, 76 insertions, 26 deletions
diff --git a/test/common/index.js b/test/common/index.js index 37327b916c..02fe9039dd 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -626,6 +626,19 @@ function expectsError(fn, settings, exact) { return mustCall(innerFn, exact); } +const suffix = 'This is caused by either a bug in Node.js ' + + 'or incorrect usage of Node.js internals.\n' + + 'Please open an issue with this stack trace at ' + + 'https://github.com/nodejs/node/issues\n'; + +function expectsInternalAssertion(fn, message) { + assert.throws(fn, { + message: `${message}\n${suffix}`, + name: 'Error', + code: 'ERR_INTERNAL_ASSERTION' + }); +} + function skipIfInspectorDisabled() { if (!process.features.inspector) { skip('V8 inspector is disabled'); @@ -729,6 +742,7 @@ module.exports = { enoughTestCpu, enoughTestMem, expectsError, + expectsInternalAssertion, expectWarning, getArrayBufferViews, getBufferSources, diff --git a/test/message/internal_assert.js b/test/message/internal_assert.js new file mode 100644 index 0000000000..fdb459b67c --- /dev/null +++ b/test/message/internal_assert.js @@ -0,0 +1,7 @@ +'use strict'; + +// Flags: --expose-internals +require('../common'); + +const assert = require('internal/assert'); +assert(false); diff --git a/test/message/internal_assert.out b/test/message/internal_assert.out new file mode 100644 index 0000000000..ae8de3e1a0 --- /dev/null +++ b/test/message/internal_assert.out @@ -0,0 +1,15 @@ +internal/assert.js:* + throw new ERR_INTERNAL_ASSERTION(message); + ^ + +Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals. +Please open an issue with this stack trace at https://github.com/nodejs/node/issues + + at assert (internal/assert.js:*:*) + at * (*test*message*internal_assert.js:7:1) + at * + at * + at * + at * + at * + at * diff --git a/test/message/internal_assert_fail.js b/test/message/internal_assert_fail.js new file mode 100644 index 0000000000..1b2cf13552 --- /dev/null +++ b/test/message/internal_assert_fail.js @@ -0,0 +1,7 @@ +'use strict'; + +// Flags: --expose-internals +require('../common'); + +const assert = require('internal/assert'); +assert.fail('Unreachable!'); diff --git a/test/message/internal_assert_fail.out b/test/message/internal_assert_fail.out new file mode 100644 index 0000000000..70f49ad33a --- /dev/null +++ b/test/message/internal_assert_fail.out @@ -0,0 +1,16 @@ +internal/assert.js:* + throw new ERR_INTERNAL_ASSERTION(message); + ^ + +Error [ERR_INTERNAL_ASSERTION]: Unreachable! +This is caused by either a bug in Node.js or incorrect usage of Node.js internals. +Please open an issue with this stack trace at https://github.com/nodejs/node/issues + + at Function.fail (internal/assert.js:*:*) + at * (*test*message*internal_assert_fail.js:7:8) + at * + at * + at * + at * + at * + at * diff --git a/test/parallel/test-internal-assert.js b/test/parallel/test-internal-assert.js index 4fd443864b..18528e9b27 100644 --- a/test/parallel/test-internal-assert.js +++ b/test/parallel/test-internal-assert.js @@ -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' }); diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index 53fbf06c77..10d79cb8fa 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -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).' ); } diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js index 9bcc63c454..925c6643a1 100644 --- a/test/parallel/test-tls-basic-validations.js +++ b/test/parallel/test-tls-basic-validations.js @@ -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' ); { diff --git a/test/sequential/test-fs-watch.js b/test/sequential/test-fs-watch.js index a67de8c6d1..fd0788dac9 100644 --- a/test/sequential/test-fs-watch.js +++ b/test/sequential/test-fs-watch.js @@ -115,14 +115,14 @@ tmpdir.refresh(); // https://github.com/joyent/node/issues/6690 { let oldhandle; - assert.throws(() => { - const w = fs.watch(__filename, common.mustNotCall()); - oldhandle = w._handle; - w._handle = { close: w._handle.close }; - w.close(); - }, { - message: 'handle must be a FSEvent', - code: 'ERR_ASSERTION' - }); + common.expectsInternalAssertion( + () => { + const w = fs.watch(__filename, common.mustNotCall()); + oldhandle = w._handle; + w._handle = { close: w._handle.close }; + w.close(); + }, + 'handle must be a FSEvent' + ); oldhandle.close(); // clean up } |