-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #26635 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
1 parent
453510c
commit dd709fc
Showing
12 changed files
with
100 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
require('../common'); | ||
|
||
const assert = require('internal/assert'); | ||
assert(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
require('../common'); | ||
|
||
const assert = require('internal/assert'); | ||
assert.fail('Unreachable!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters